Tag: python 3.x

从Docker容器执行本地机器上的命令

我有docker容器正在监听连接,并在实际主机上执行iptables规则。 我怎样才能从docker容器运行命令才能在实际的主机上生效。 例如: Host-A (Ubuntu) -> Docker (docker-machine) -> my-container (alpine) 从上面的例子 – 我想在my-container运行iptables命令来应用在Host-A 。

捕获docker容器内的shell脚本的输出到使用docker sdk for python的文件)

我有一个名为test.sh docker容器中有一个shell脚本。 我想把这个脚本的输出传给一个文件。 我可以使用docker exec命令或通过login到shell(使用./test.sh > test.txt )并运行./test.sh > test.txt 。 但是,我想知道如何使用docker sdk for python实现相同的结果。 这是我的代码到目前为止: import docker client = docker.APIClient(base_url='unix://var/run/docker.sock') container= client.create_container( 'ubuntu:16.04', '/bin/bash', stdin_open=True, tty=True, working_dir='/home/psr', \ volumes=['/home/psr/data'], \ host_config=client.create_host_config(binds={ '/home/xxxx/data_generator/data/': { 'bind': '/home/psr/data', 'mode': 'rw', }, }) ) client.start(container=container.get('Id')) cmds= './test.sh > test.txt' exe=client.exec_create(container=container.get('Id'), cmd= cmds, stdout=True) exe_start=client.exec_start(exec_id=exe, stream=True) for val in […]

configparser:不从给定path读取文件

下面是我在Eclipse中的python项目结构。 我正在使用configparser来读取settings.config文件中的一个部分。 configparser不parsing文件。 它显示没有指定的部分,但我已经正确地提到该部分。 我正在创build一个dockerfile,当我运行docker-compose文件时,path显示为 /usr/local/lib/python3.6/site-packages/MyProject-0.0.1-py3.6.egg/Publisher/settings.config MyProject -Client -__init__.py -Main.py -Publisher -domain1 -domain2 -__init__.py -config.py -callconfig.py -__init__.py -settings.config #config.py import os.path as path try: from configparser import ConfigParser except ImportError: from ConfigParser import ConfigParser # ver. < 3.0 class Config(object): def get(self, mykey): config = ConfigParser() configpath = path.join(path.split(path.dirname(path.abspath(__file__)))[0], "settings.config") print (configpath) config.read(configpath) myvalue = […]

如何将库作为docker容器服务运行?

我想使用PyPandoc作为服务(在Docker容器中)。 我安装了“docker pull msabramo / pypandoc”。 它创build一个图像,但我不知道如何使用它(input到Docker容器并获得输出)。 我应该从那里打字?

试图在Docker镜像上安装selenium python3软件包

我试过用selenium python包重新构build一个Docker镜像失败。 我不知道如何继续。 这是我的dockerfile: FROM selenium/standalone-chrome:latest WORKDIR /usr/local/bin RUN sudo apt-get update RUN sudo apt-get install software-properties-common RUN sudo apt-add-repository universe RUN sudo apt-get install python-pip RUN pip3 install -r requirements.txt RUN pip3 install . RUN pip3 install -e . COPY ./* ./ 我相当确定这是我的dockerfile是错误的,但尝试各种安装点的方法后,我画了一个空白。 在任何情况下,我然后调用:docker build -t webdriver。 其中输出以下内容: Sending build context to Docker daemon […]

在Docker镜像上开发抓取脚本 – 如何克服视觉浏览器的不足?

我想从网上抓取信息,以前的一个尝试教会了我,docker工作将会对我的脚本运行起到很大的作用,因为我在mac os x上开发脚本,然后在vm上运行它,通常它不会运行因为Ubuntu的依赖关系并不存在,而且已经certificate很难构build。 Docker克服了依赖性问题,但是现在我又面临一个不同的问题,那就是我需要在Docker镜像上以非无头模式开发脚本,看看它在做什么(或者至less我认为我是这样做的),而是在docker上不要认为可以在非无头模式下运行浏览器。 别人如何克服这个问题或以其他方式绕过它? 我在@Harald Norgren帮助我在这个图像上使用python3,selenium 这是我正在运行的脚本,但它还没有做任何事情,我只是包括它提供更多的背景,这是有帮助的。 import csv import time from selenium import webdriver import os import logging #logging.warning(data_store+file) import json project_dir = os.path.dirname(os.path.realpath(__file__)) data_store = project_dir+"/trends-data/" archive_folder = "archive" data_archive = data_store + archive_folder + "/" chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("–headless") prefs = {"download.default_directory" : data_store} chromeOptions.add_experimental_option("prefs",prefs) driver = webdriver.Chrome( project_dir+'/chromedriver', chrome_options=chromeOptions ) […]

安装Python 3 Docker Ubuntu错误命令'x86_64-linux-gnu-gcc

我正在尝试创build一个使用Python 3的dockerfile。 FROM ubuntu:14.04 RUN apt-get update RUN apt-get install -y python3 python3-dev python-pip RUN apt-get install -y libxml2-dev libxslt1-dev libpq-dev libjpeg-dev libfreetype6-dev zlib1g-dev RUN cd /var/projects/apps && pip install -r requirements.txt 我得到的错误致命错误:Python.h:没有这样的文件或目录时,试图安装枕头在我的要求,为什么,我是我正确安装python 3? error: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 —————————————- Cleaning up… Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), […]

在dockerized python3 ftp命令中RETR引发ConnectionResetError

我尝试通过ftp从一个python3docker容器中下载一个文件,该容器是从官方的docker中心Python库build立的。 下面是我尝试执行的python代码的一个简单例子: import ftplib ftp = ftplib.FTP("ftp.geneontology.org") ftp.login() ftp.sendcmd("MDTM /go/ontology/go-basic.obo") ftp.retrbinary("RETR /go/ontology/go-basic.obo", callback=open("go-basic.obo", "wb").write) 该代码的MDTM和RETR命令在主机中运行良好。 但是,在python3 docker容器中,只有MDTM命令有效。 RETR命令会引发以下错误消息: >>> ftp.retrbinary("RETR /go/ontology/go-basic.obo", callback=open("ich.obo", "wb").write) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/ftplib.py", line 443, in retrbinary data = conn.recv(blocksize) ConnectionResetError: [Errno 104] Connection reset by peer >>> 我的Dockerfile看起来像这样: FROM python:3 CMD […]

如何创build在Ubuntu容器中安装Python 3和nltk的Dockerfile?

我正在尝试使用python 3和nltk tokenizer创build一个Docker容器。 任何人都可以帮助我创buildDockerfile。

我的Procfile应该如何?

我想部署在Heroku我的项目在Docker与Angular 4前端,Django的后端和postgresql数据库。 在这个时候我的文件看起来如下所示。 我收到错误: 2017-07-10T19:44:39.000000+00:00 app[api]: Build succeeded 2017-07-10T19:45:19.954230+00:00 heroku[web.1]: Starting process with command `gunicorn pri.wsgi` 2017-07-10T19:45:22.834045+00:00 app[web.1]: [2017-07-10 19:45:22 +0000] [4] [INFO] Starting gunicorn 19.7.1 2017-07-10T19:45:22.834597+00:00 app[web.1]: [2017-07-10 19:45:22 +0000] [4] [INFO] Listening at: http://0.0.0.0:53621 (4) 2017-07-10T19:45:22.834712+00:00 app[web.1]: [2017-07-10 19:45:22 +0000] [4] [INFO] Using worker: sync 2017-07-10T19:45:22.838348+00:00 app[web.1]: [2017-07-10 19:45:22 +0000] [8] [INFO] Booting […]