We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker构建镜像的2个条件
docker build .
Dockerfile
-f
.
用来忽略上下文中构建用不到的目录文件,语法同.gitignore
CMD
ENTRYPOINT
FROM debian:wheezy ENTRYPOINT ["/bin/ping"] CMD ["localhost", "-c", "2"]
以上Dockerfile,将接受CMD作为ENTRYPOINT命令的缺省参数
不带参数执行结果
➜ /Users/linqiong/workspace/docker/example docker run -it --rm example PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.066 ms 64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.137 ms --- localhost ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1023ms rtt min/avg/max/mdev = 0.066/0.101/0.137/0.036 ms
带参数(覆盖CMD)执行结果
➜ /Users/linqiong/workspace/docker/example docker run -it --rm example www.baidu.com PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38: icmp_req=1 ttl=37 time=34.7 ms 64 bytes from 14.215.177.38: icmp_req=2 ttl=37 time=35.3 ms 64 bytes from 14.215.177.38: icmp_req=3 ttl=37 time=34.2 ms 64 bytes from 14.215.177.38: icmp_req=4 ttl=37 time=34.1 ms 64 bytes from 14.215.177.38: icmp_req=5 ttl=37 time=32.8 ms ^C --- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4012ms rtt min/avg/max/mdev = 32.812/34.260/35.353/0.847 ms
参考:
COPY
ADD
如果仅仅用于复制文件,请选择 COPY,简单更有效。 如果需要提取存档,需要使用 ADD。
# 比如将一个local 的包解压,通过 COPY 命令,执行如下,需要三步 # 这里用 COPY,其实是个错误的选择 RUN mkdir -p /usr/java COPY resource/jdk1.8.0_77.tgz /usr/java/jdk1.8.0_77.tgz RUN tar -zxvf /usr/java/jdk1.8.0_77.tgz -C /usr/java # 用 ADD 命令,一步到位 ADD resource/jdk1.8.0_77.tgz /usr/java
The text was updated successfully, but these errors were encountered:
lqshow
No branches or pull requests
构建
docker构建镜像的2个条件
构建命令
docker build .
Dockerfile
一般位于构建上下文的根目录下,也可以通过-f
指定该文件的位置.
,表示当前目录,是指定上下文路径Comand Options
.dockerignore
用来忽略上下文中构建用不到的目录文件,语法同.gitignore
相关问题
Dockerfile中的
CMD
和ENTRYPOINT
有什么区别CMD
和ENTRYPOINT
指令都定义了在运行容器时执行的命令ENTRYPOINT
指定一个在容器启动时总是执行的命令。CMD
当容器启动时运行的命令或者指定了ENTRYPOINT的参数。以上Dockerfile,将接受CMD作为
ENTRYPOINT
命令的缺省参数➜ /Users/linqiong/workspace/docker/example docker run -it --rm example PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.066 ms 64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.137 ms --- localhost ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1023ms rtt min/avg/max/mdev = 0.066/0.101/0.137/0.036 ms
➜ /Users/linqiong/workspace/docker/example docker run -it --rm example www.baidu.com PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38: icmp_req=1 ttl=37 time=34.7 ms 64 bytes from 14.215.177.38: icmp_req=2 ttl=37 time=35.3 ms 64 bytes from 14.215.177.38: icmp_req=3 ttl=37 time=34.2 ms 64 bytes from 14.215.177.38: icmp_req=4 ttl=37 time=34.1 ms 64 bytes from 14.215.177.38: icmp_req=5 ttl=37 time=32.8 ms ^C --- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4012ms rtt min/avg/max/mdev = 32.812/34.260/35.353/0.847 ms
参考:
Dockerfile中的
COPY
和ADD
命令有什么区别COPY
只支持将本地文件复制到容器中ADD
具有额外的功能(如仅限本地的tar提取和远程URL支持)如果仅仅用于复制文件,请选择 COPY,简单更有效。
如果需要提取存档,需要使用 ADD。
The text was updated successfully, but these errors were encountered: