One - One Code All

Blog Content

Docker build ubuntu无法执行apt-get update, Failed to fetch,Temporary failure resolving archive.ubuntu.com

Linux-Mac 容器化   2018-12-23 17:20:33

Docker build的时候出现:


Reading package lists...

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease  Temporary failure resolving 'security.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'mirrors.aliyun.com'

W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/focal-updates/InRelease  Temporary failure resolving 'mirrors.aliyun.com'

W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/focal-backports/InRelease  Temporary failure resolving 'mirrors.aliyun.com'

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease  Temporary failure resolving 'security.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

Reading package lists...

Building dependency tree...

Reading state information...

E: Unable to locate package python3

E: Unable to locate package python3-dev

E: Unable to locate package python3-pip

E: Unable to locate package iputils-ping

E: Unable to locate package vim

E: Unable to locate package curl



方法1:替换源:


RUN sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.163\.com\/ubuntu\//g' /etc/apt/sources.list

RUN sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.aliyun\.com\/ubuntu\//g' /etc/apt/sources.list


方法2:

docker build 指定 --network=host


docker build --network=host -t ubuntu20-python:1.0.0 .




Docker build 命令:


docker build [OPTIONS] PATH | URL | 



OPTIONS说明:


--build-arg=[] :设置镜像创建时的变量;


--cpu-shares :设置 cpu 使用权重;


--cpu-period :限制 CPU CFS周期;


--cpu-quota :限制 CPU CFS配额;


--cpuset-cpus :指定使用的CPU id;


--cpuset-mems :指定使用的内存 id;


--disable-content-trust :忽略校验,默认开启;


-f :指定要使用的Dockerfile路径;


--force-rm :设置镜像过程中删除中间容器;


--isolation :使用容器隔离技术;


--label=[] :设置镜像使用的元数据;


-m :设置内存最大值;


--memory-swap :设置Swap的最大值为内存+swap,"-1"表示不限swap;


--no-cache :创建镜像的过程不使用缓存;


--pull :尝试去更新镜像的新版本;


--quiet, -q :安静模式,成功后只输出镜像 ID;


--rm :设置镜像成功后删除中间容器;


--shm-size :设置/dev/shm的大小,默认值是64M;


--ulimit :Ulimit配置。


--squash :将 Dockerfile 中所有的操作压缩为一层。


--tag, -t: 镜像的名字及标签,通常 name:tag 或者 name 格式;可以在一次构建中为一个镜像设置多个标签。


--network: 默认 default。在构建期间设置RUN指令的网络模式



上一篇:linux命令行使用python json.tool将结果标准化输出
下一篇:Mac 上 brew 安装Tomcat

The minute you think of giving up, think of the reason why you held on so long.