Tag: python

保存从Docker容器内部抓取的数据csv文件到本地主机

我运行一个python webscraper来收集关于各种网站的文章,然后保存为csv文件。 我一直在手动运行这些,但最近一直试图在谷歌云壳中运行它们。 我有一些依赖关系的麻烦,所以我决定build立一个docker图像来运行我的python刮板 到目前为止,我已经设法创build了一个Dockerfile,用于构build具有所有必需依赖项的容器。 FROM python:3 # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app ADD . /app # Install any needed packages specified in requirements.txt RUN pip install –trusted-host pypi.python.org -r requirements.txt RUN pip install lxml COPY Fin24 ./Fin24 COPY scraped_list.csv ./scraped_list.csv […]

尝试在Docker中的Django中运行python脚本

我试图运行我的python脚本,它使用了一些在docker容器中的django里面定义的模型。 我使用以下命令: sudo docker-compose -f production.yml run django python manage.py shell < send.py 但是我一直得到这个错误: IndentationError: unexpected indent File "<console>", line 1 stats = grp_px.calc_stats(dropna=False) ^ IndentationError: unexpected indent File "<console>", line 1 st = stats.render_perf(key=key) ^ IndentationError: unexpected indent File "<console>", line 1 perf_list.append([key, st.render()]) ^ IndentationError: unexpected indent File "<console>", line 1 send_mail(html_message=render_to_string('fund_vs_peers.html', {'perf_list': […]

为nginx,uwsgi,django构builddocker容器是一个好方法

我有一个方法,使用基本的操作系统映像来构build一个容器内的nginx,uwsgi,django,以便在云服务上快速部署网站。 而且我也成功地构build了一个反向代理来指向不同的Django应用程序,但仍然在一个容器内。 这种方法的缺点是,当我更新一个服务或应用程序时,我需要彻底销毁整个容器,并创build一个包含所有服务的新容器。 因此,我想为nginx,uwsgi构build一个容器,每个django应用程序都有一个容器。 总之,我想分开的应用程序和服务每个容器。 大部分教程在线将这样的组合部署在一个容器内。 所以我的问题是什么是最好的方法呢? 对于像nginx,uwsgi这样的服务,我应该在没有基础操作系统映像的情况下构build它们,而只是构build服务映像,或者我应该使用基本操作系统映像构build它们,然后将服务添加到顶层? 另外,对于我的Django应用程序,我应该为每个应用程序构build一个基本的操作系统映像,或者只是用python映像启动基础?

tf.contrib.signal.stft返回一个空matrix

这是我运行的代码片段: import tensorflow as tf sess = tf.InteractiveSession() filename = 'song.mp3' # 30 second mp3 file SAMPLES_PER_SEC = 44100 audio_binary = tf.read_file(filename) pcm = tf.contrib.ffmpeg.decode_audio(audio_binary, file_format='mp3', samples_per_second=SAMPLES_PER_SEC, channel_count = 1) stft = tf.contrib.signal.stft(pcm, frame_length=1024, frame_step=512, fft_length=1024) sess.close() 由于print(pcm.eval().shape)返回,所以mp3文件被正确解码: (1323119, 1) 当我使用print(pcm.eval()[1000:1010])时,甚至有一些实际的非零值: [[ 0.18793298] [ 0.16214484] [ 0.16022217] [ 0.15918455] [ 0.16428113] [ 0.19858395] [ 0.22861415] […]

我如何在Docker中运行cron? (即使使用简单的crontab也没有作业/输出)

我试图把一个cronjob放在我的docker容器里面,它运行一个python脚本。 我的Dockerfile: FROM python:3.6.2 RUN apt-get update && apt-get -y install cron ADD . /dir WORKDIR /dir RUN pip install -r requirements.txt RUN chmod 0644 /dir ADD crontab /dir ENV NAME loader CMD cron -f 我的crontab文件: * * * * * root /loader.py 正如我运行: $ docker run -t -i loader:latest 10分钟后我什么也得不到。 脚本在运行时写出Hello World。 我从docker镜像中删除了cron,脚本工作并写出Hello world […]

一旦容器完成处理,如何自动停止虚拟机?

我有一台运行docker容器的centos 7机器。 现在我正在login到vm来检查已完成处理的容器并退出。 有没有办法检查机器是否正在运行容器,如果所有的容器退出,应该让我知道所有的容器退出,虚拟机应该自动停止状态。 在这种情况下,我正在使用azure虚拟机,因为我有很多虚拟机运行,检查每个虚拟机是不是正确的解决scheme。 请澄清这个问题… Thx,Arun

Docker容器停止响应networking调用

我有我的Django应用程序运行在docker容器内使用gunicorn。 随机,容器停止响应networking调用。 容器正在运行。 我也检查了统计信息的CPU或内存使用情况,他们似乎没有问题。 我的docker版本: Client: Version: 1.13.0 API version: 1.25 Go version: go1.7.3 Git commit: 49bf474 Built: Tue Jan 17 09:50:17 2017 OS/Arch: linux/amd64 Server: Version: 1.13.0 API version: 1.25 (minimum version 1.12) Go version: go1.7.3 Git commit: 49bf474 Built: Tue Jan 17 09:50:17 2017 OS/Arch: linux/amd64 Experimental: false curl指令响应: * Hostname was NOT […]

Docker图像与uWSGI / Gunicorn + Nginx的Flask应用程序在CentOS

我一直在寻找互联网,find任何与uWSGI或Gunicorn和Nginx合作为CentOS 7环境中的Flask应用程序提供Docker镜像的示例。 我发现最近的是这个 ,它基于Ubuntu。 我如何重新编写Dockerfile来使用C​​entOS 7而不是Ubuntu: FROM ubuntu:14.04 MAINTAINER Phillip Bailey <phillip@bailey.st> ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y \ python-pip python-dev uwsgi-plugin-python \ nginx supervisor COPY nginx/flask.conf /etc/nginx/sites-available/ COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY app /var/www/app RUN mkdir -p /var/log/nginx/app /var/log/uwsgi/app /var/log/supervisor \ && rm /etc/nginx/sites-enabled/default \ && ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf \ […]

Python2subprocess不会将Ctrl-C信号传递到具有交错标准输出stderr的docker容器

我有一个python 2subprocess,启动docker容器,并尝试交错stdout和stderr: from subprocess import check_output, Popen, PIPE, STDOUT from threading import Thread command_args = [ "docker", "run", "-i", "–rm", '–entrypoint', 'sleep', # Pretend long running task 'ubuntu:trusty', '20' ] print('Running subprocess') p = Popen(command_args, stdin=PIPE, stdout=PIPE, stderr=PIPE) def log_pipe(pipe): for line in iter(pipe.readline, b''): print(line.rstrip()) stdout_thread = Thread(target=log_pipe, args=[p.stdout]) stderr_thread = Thread(target=log_pipe, args=[p.stderr]) stdout_thread.start() […]

使用Django 2.0构buildDocker镜像失败

我目前正在用最新版本的Django构build一个docker镜像,但是在构build过程中,我得到了这个: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9LueOB/Django/ You are using pip version 8.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install –upgrade pip' command. The command '/bin/sh -c INSTALL_PKGS="python-pip oracle-instantclient-tnsnames.ora afs_tools_standalone nss_wrapper openssh-clients cx_Oracle libmemcached-devel python-ldap mod_wsgi httpd MySQL-python wassh-ssm-cern wassh" && INSTALL_PKGS_BUILD="gcc python-devel zlib-devel" […]