Construction Dockerfile mirror (II)

Preparing the Environment

Server system Centos7.3
RAM 1G
CPU 2 nuclear
IP addresses 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

Here Insert Picture Description

docker build -t centos:1.1 ./
docker run --rm -it centos:1.1   /bin/bash  
pwd
ls

Here Insert Picture Description

cd /usr/local/src/
ls
exit

Here Insert Picture Description

vim Dockerfile 
FROM centos
CMD "echo hello aaronszm"
docker build -t centos:1.2 ./

Here Insert Picture Description

docker run centos:1.2
docker run centos:1.2 echo 123

Here Insert Picture Description

vim Dockerfile 

FROM centos
CMD ["echo","hello","aaronszm"]

Here Insert Picture Description

docker build -t centos:1.3 ./
docker run centos:1.3

Here Insert Picture Description

vim Dockerfile 

FROM centos
ENTRYPOINT ["echo","王麻子"]

Here Insert Picture Description

docker build -t centos:1.4 ./
docker run --rm centos:1.4
docker run --rm centos:1.4 echo tom
echo "王麻子 echo tom"

Here Insert Picture Description

vim Dockerfile 
FROM centos
CMD ["echo","jack"]
ENTRYPOINT ["echo","王麻子"]

Here Insert Picture Description

docker build -t centos:1.5 ./
docker run --rm centos:1.5

Here Insert Picture Description

So when CMD and ENTRYPOINT exist, then the CMD will only be a formal parameter passed to ENTRYPOINT, will not go alone executed!

Here Insert Picture Description

vim Dockerfile 
FROM centos
CMD ["echo","jack"]
CMD ["tom","lucy"]
ENTRYPOINT ["echo","王麻子"]

Here Insert Picture Description

docker build -t centos:1.6 ./
docker run --rm centos:1.6

Here Insert Picture Description

Here Insert Picture Description

docker run --rm centos:1.6 张德帅

Here Insert Picture Description

vim Dockerfile 
FROM centos
ENTRYPOINT ["echo","$NAME"]

Here Insert Picture Description

docker build -t centos:1.7 ./
docker run --rm -e NAME=lucy centos:1.7
vim Dockerfile
FROM centos
ENTRYPOINT ["echo",$NAME]

Here Insert Picture Description

build -t centos:1.8 ./
docker run --rm -e NAME=lucy centos:1.8

Here Insert Picture Description

vim Dockerfile 
FROM centos
ENTRYPOINT echo $NAME

Here Insert Picture Description

docker build -t centos:1.9 ./
docker run --rm -e NAME=lucy centos:1.9

Here Insert Picture Description

vim Dockerfile 
FROM centos
ENV NAME=tom

ENTRYPOINT echo $NAME

Here Insert Picture Description

docker build -t centos:2.0 ./
docker run --rm centos:2.0
docker run --rm -e NAME=lucy centos:2.0

Here Insert Picture Description

Published 108 original articles · won praise 30 · views 40000 +

Guess you like

Origin blog.csdn.net/aaronszm/article/details/104315254