https://github.com/docker/labs/blob/master/developer-tools/java/chapters/ch03-build-image.adoc
- 这篇文章介绍了如何构架docker镜像;
- 通过dockerfile创建docker镜像,dockerfile中有相关指令;
- 常用命令:
作用 例子 ROM Dockerfile中第一条命令 OPY 拷贝文件到容器指定目录 NV 设置环境变量 UN 执行命令 MD 执行容器命令 XPOSE 指定监听端口 - 创建一个目录hellodocker,创建一个Dockerfile
FROM ubuntu:latest CMD ["/bin/echo", "hello world"] - 创建镜像
docker image build . -t helloworld输出Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM ubuntu:latest
latest: Pulling from library/ubuntu
9fb6c798fa41: Pull complete
3b61febd4aef: Pull complete
9d99b9777eb0: Pull complete
d010c8cf75d7: Pull complete
7fac07fb303e: Pull complete
Digest: sha256:31371c117d65387be2640b8254464102c36c4e23d2abe1f6f4667e47716483f1
Status: Downloaded newer image for ubuntu:latest
—> 2d696327ab2e
Step 2/2 : CMD /bin/echo hello world
—> Running in 9356a508590c
—> e61f88f3a0f7
Removing intermediate container 9356a508590c
Successfully built e61f88f3a0f7
Successfully tagged helloworld:latest - 通过查看镜像,可以看到 docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE helloworld latest e61f88f3a0f7 3 minutes ago 122MB ubuntu latest 2d696327ab2e 4 days ago 122MB - 通过命令行创建容器,可以看到输出了hello world
输出:docker container run helloworldhello world
版权声明:本文为VitaminZH原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。