【发布时间】:2018-08-04 22:43:12
【问题描述】:
我需要在 Docker 中实现一个简单的 python 应用程序。 我按照指示:https://docs.docker.com/get-started/part2/#dockerfile
我运行这样的构建命令:
sudo docker build -t sender .
我的 requirements.txt 如下所示:
pika==0.11.2
并且 Dockerfile 包含以下内容(上面教程中的代码)
# Use an official Python runtime as a parent image
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
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
运行时pip无法安装pika:
sudo docker build -t sender .
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM python:3
---> 336d482502ab
Step 2/7 : WORKDIR /app
---> Using cache
---> 9b0ffaad3d8c
Step 3/7 : ADD . /app
---> Using cache
---> 42aa7eb4ab74
Step 4/7 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
---> Running in 24a3943a217b
Collecting pika==0.11.2 (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f9911830668>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pika/
我尝试安装 numpy 而不是 pika,但遇到了同样的问题。然后我用谷歌搜索并了解问题出在防火墙上。
首先我尝试这样运行 (https://github.com/docker/compose/issues/2111):
sudo docker build --build-arg HTTP_PROXY=$HTTP_PROXY -t sender .
然后我尝试关闭代理:
sudo ufw disable
我还尝试从 Dockerfile 中删除 requirements.txt 并将其替换为 pip install pika。
没有任何帮助。
【问题讨论】:
标签: python docker pip docker-compose dockerfile