在centos7主机上构建docker镜像的时候写了如下的Dockerfile
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y python-pip
RUN apt-get clean all
RUN pip install flask
ADD hello.py /tmp/hello.py
EXPOSE 5000
CMD ["python","/tmp/hello.py"]
使用docker build -t flask .命令构建的时候命令行报如下错误
Step 2/9 : RUN apt-get update
---> Running in 0eec7173f903
Ign https://esm.ubuntu.com trusty-infra-security InRelease
Err http://archive.ubuntu.com trusty InRelease
Err http://archive.ubuntu.com trusty-updates InRelease
Err http://archive.ubuntu.com trusty-backports InRelease
Err http://archive.ubuntu.com trusty Release.gpg
Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-backports Release.gpg
Could not resolve 'archive.ubuntu.com'
Err http://security.ubuntu.com trusty-security InRelease
解析出现了问题,查了一些攻略,终于可以了。
在/etc/sysconfig/docker这个文件中,增加一行
# docker-latest daemon can be used by starting the docker-latest unitfile.
# To use docker-latest client, uncomment below lines
#DOCKERBINARY=/usr/bin/docker-latest
#DOCKERDBINARY=/usr/bin/dockerd-latest
#DOCKER_CONTAINERD_BINARY=/usr/bin/docker-containerd-latest
DOCKER_OPTS="–dns 8.8.8.8 –dns 8.8.4.4"
#DOCKER_CONTAINERD_SHIM_BINARY=/usr/bin/docker-containerd-shim-latest
然后重启docker服务
systemctl restart docker
重新运行构建命令
docker build -t flask .
apt-get命令运行正常
Step 2/9 : RUN apt-get update
---> Running in 21b68558cd3fGet:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
Ign http://archive.ubuntu.com trusty InRelease
Get:2 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:3 https://esm.ubuntu.com trusty-infra-security InRelease
Get:4 http://security.ubuntu.com trusty-security/main amd64 Packages [1032 kB]
Get:5 https://esm.ubuntu.com trusty-infra-updates InRelease
Get:6 http://archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Get:7 https://esm.ubuntu.com trusty-infra-security/main amd64 Packages
Hit http://archive.ubuntu.com trusty Release.gpg
Get:8 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1460 kB]
Get:9 https://esm.ubuntu.com trusty-infra-updates/main amd64 Packages
Get:10 http://security.ubuntu.com trusty-security/restricted amd64 Packages [18.1 kB]
Get:11 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [21.4 kB]
Get:12 http://security.ubuntu.com trusty-security/universe amd64 Packages [378 kB]
Get:13 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [671 kB]
Get:14 http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages [16.1 kB]
Get:15 http://archive.ubuntu.com trusty-backports/main amd64 Packages [14.7 kB]
Get:16 http://archive.ubuntu.com trusty-backports/restricted amd64 Packages [40 B]
Get:17 http://security.ubuntu.com trusty-security/multiverse amd64 Packages [4730 B]
Get:18 http://archive.ubuntu.com trusty-backports/universe amd64 Packages [52.5 kB]
Get:19 http://archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1392 B]
Hit http://archive.ubuntu.com trusty Release
Get:20 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB]
Get:21 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB]
Get:22 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB]
Get:23 http://archive.ubuntu.com trusty/multiverse amd64 Packages [169 kB]
Fetched 14.1 MB in 8s (1588 kB/s)
Reading package lists...
---> e606d6bd2677
Removing intermediate container 21b68558cd3f
Step 3/9 : RUN apt-get install -y python
---> Running in 8d1252079ae3
就是解析的问题,要给docker配置文件添加dns的服务器地址。