我无法在构建图像时安装任何软件包。从docker hub拉出来是可以的,但是当docker尝试使用网络来构建映像时会出现问题。例如,如果我尝试运行:
$ docker build -t sample-image:latest .
...并且上面命令使用的Dockerfile有以下行:
RUN pip install -r requirements.txt
...然后我得到下一个错误:
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fdbe102e278>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/sanic/
Could not find a version that satisfies the requirement sanic (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for sanic (from -r requirements.txt (line 1))
...当ubuntu软件包正在更新时出现相同的错误
docker和docker compose由官方docker的文档安装(没有任何更改)。
Server Version: 17.03.1-ce
Storage Driver: aufs
Kernel Version: 4.8.0-45-generic
Operating System: Ubuntu 16.04.2 LTS
Architecture: x86_64
CPUs: 2
Total Memory: 3.763 GiB
requirements.txt:
sanic
asyncpg
asyncio
uvloop
Dockerfile:
FROM python:3.5-onbuild
WORKDIR /usr/src/app
# https://github.com/vishnubob/wait-for-it
CMD ["./run/wait-for-it.sh", "db:5432", "--", "python", "index.py"]
我测试了更多的决定而没有人帮助过。感谢大家的帮助:)。
答案 0 :(得分:1)
谢谢Salem!以下决定帮助了我:
尝试编辑/etc/NetworkManager/NetworkManager.conf并注释掉 dns = dnsmasq部分,重新启动网络和docker并再试一次
答案 1 :(得分:0)
如果在主机上安装软件包时 pip install 成功,但在 docker build 期间没有成功,那么对我有用的解决方案是将主机 index-url
中的 /etc/pip.conf
存在于 docker 中图像。
示例:
如果主机的 /etc/pip.conf
包含:
index-url = https://example.com/blah/blah/blah
然后在安装任何 pip 包之前将以下行添加到 Dockerfile
中:
RUN echo '[global]\nindex-url = https://example.com/blah/blah/blah\ntrusted-host = https://example.com' > /etc/pip.conf