环境准备
服务器系统 | Centos7.3 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.43 |
mkdir Dockerfile
cd Dockerfile/
vim Dockerfile
FROM centos
WORKDIR /usr/local/src
RUN touch hello
WORKDIR /usr/share
RUN touch aaronszm
docker build -t centos:1.1 ./
docker run --rm -it centos:1.1 /bin/bash
pwd
ls
cd /usr/local/src/
ls
exit
vim Dockerfile
FROM centos
CMD "echo hello aaronszm"
docker build -t centos:1.2 ./
docker run centos:1.2
docker run centos:1.2 echo 123
vim Dockerfile
FROM centos
CMD ["echo","hello","aaronszm"]
docker build -t centos:1.3 ./
docker run centos:1.3
vim Dockerfile
FROM centos
ENTRYPOINT ["echo","王麻子"]
docker build -t centos:1.4 ./
docker run --rm centos:1.4
docker run --rm centos:1.4 echo tom
echo "王麻子 echo tom"
vim Dockerfile
FROM centos
CMD ["echo","jack"]
ENTRYPOINT ["echo","王麻子"]
docker build -t centos:1.5 ./
docker run --rm centos:1.5
所以说当CMD 和 ENTRYPOINT同时存在的时候,那么CMD只会是一个参数的形式传递给ENTRYPOINT,不会再单独去执行了!
vim Dockerfile
FROM centos
CMD ["echo","jack"]
CMD ["tom","lucy"]
ENTRYPOINT ["echo","王麻子"]
docker build -t centos:1.6 ./
docker run --rm centos:1.6
docker run --rm centos:1.6 张德帅
vim Dockerfile
FROM centos
ENTRYPOINT ["echo","$NAME"]
docker build -t centos:1.7 ./
docker run --rm -e NAME=lucy centos:1.7
vim Dockerfile
FROM centos
ENTRYPOINT ["echo",$NAME]
build -t centos:1.8 ./
docker run --rm -e NAME=lucy centos:1.8
vim Dockerfile
FROM centos
ENTRYPOINT echo $NAME
docker build -t centos:1.9 ./
docker run --rm -e NAME=lucy centos:1.9
vim Dockerfile
FROM centos
ENV NAME=tom
ENTRYPOINT echo $NAME
docker build -t centos:2.0 ./
docker run --rm centos:2.0
docker run --rm -e NAME=lucy centos:2.0
来源:CSDN
作者:aaronszm
链接:https://blog.csdn.net/aaronszm/article/details/104315254