dockerfile指令说明

2020-01-08  本文已影响0人  何妨吟啸且徐行1

>> 示例<<

FROM centos:7.1
MAINTAINER M_G
LABEL im_name="my_centos7"\
      im_desc="centos7.1byM_G"\
      im_version="1.0"
RUN /bin/echo "Testing-RUN1"\
    /bin/echo "Testing-RUN2"\
    /bin/echo "Testing-RUN3"\
    /bin/echo "The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile"
RUN ["/bin/echo", "-c", "OtherMeth"]
EXPOSE 7788
CMD /bin/echo "CMD"

>> 示例运行结果 <<

docker build -t runtest/centos:7.1 .
Sending build context to Docker daemon  2.048kB
Step 1/7 : FROM centos:7.2.1511
 ---> 9aec5c5fe4ba
Step 2/7 : MAINTAINER M_G
 ---> Running in fd9773ab5d04
Removing intermediate container fd9773ab5d04
 ---> 5d049cf44ade
Step 3/7 : LABEL im_name="my_centos7"      im_desc="centos7.1byM_G"   im_version="1.0"
 ---> Running in dbe78be6937a
Removing intermediate container dbe78be6937a
 ---> 835de35557c0
Step 4/7 : RUN /bin/echo "Testing-RUN1" /bin/echo "Testing-RUN2"    /bin/echo "Testing-RUN3"    /bin/echo "The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile"
 ---> Running in 200e155ce261
Testing-RUN1 /bin/echo Testing-RUN2 /bin/echo Testing-RUN3 /bin/echo The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile
Removing intermediate container 200e155ce261
 ---> 6b20860bc949
Step 5/7 : RUN ["/bin/echo", "-c", "OtherMeth"]
 ---> Running in 39064900f238
-c OtherMeth
Removing intermediate container 39064900f238
 ---> 47e32cba5448
Step 6/7 : EXPOSE 7788
 ---> Running in c658c7ba76ea
Removing intermediate container c658c7ba76ea
 ---> e76255a7950f
Step 7/7 : CMD /bin/echo "CMD"
 ---> Running in 9ab1ff69c36d
Removing intermediate container 9ab1ff69c36d
 ---> 91f66f06b528
Successfully built 91f66f06b528
Successfully tagged runtest/centos:7.1

完成以上指令,docker images已经创建成功,测试一下:

docker run -t -i runtest/centos:7.1 /bin/echo "TEST"
# output
TEST
上一篇下一篇

猜你喜欢

热点阅读