目录
🦐博客主页:大虾好吃吗的博客
🦐专栏地址:云原生专栏
dockerfile是什么
docker中并不建议用户通过commit方式来构建镜像,主要原因如下:
-
这是一种手工创建镜像的方式,容易出错,效率低且可重复性弱。比如要在 debian base 镜像中也加入vi,还得重复前面的所有步骤。
-
更重要的:使用者并不知道镜像是如何创建出来的,里面是否有恶意程序。也就是说无法对镜像进行审计,存在安全隐患。
用 Dockerfile(推荐方法)构建镜像,底层也 docker commit 一层一层构建新镜像的。docker commit 能够帮助我们更加深入地理解构建过程和镜像的分层结构。
强烈推荐看官方文档:MySQL官方dockerfile文档
用 Dockerfile(推荐方法)构建镜像,底层也 docker commit 一层一层构建新镜像的。docker commit 能够帮助我们更加深入地理解构建过程和镜像的分层结构。
下面来个小案例,使用centos:7来构建系统镜像,里面安装vim(默认里面仅支持vi)。下面使用buid构建镜像,os1镜像名,“ . ”是dockerfile的路径
[root@localhost ~]# mkdir doc_file
[root@localhost ~]# cd doc_file/
[root@localhost doc_file]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 16 months ago 141MB
httpd latest dabbfbe0c57b 16 months ago 144MB
centos 7 eeb6ee3f44bd 19 months ago 204MB
[root@localhost doc_file]# vim dockerfile
FROM centos:7
RUN yum -y install vim
[root@localhost doc_file]# docker build -t os1 .
[+] Building 110.7s (6/6) FINISHED
=> [internal] load build definition from dockerfile 0.0s
=> => transferring dockerfile: 74B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/centos:7 0.0s
=> CACHED [1/2] FROM docker.io/library/centos:7 0.0s
=> [2/2] RUN yum -y install vim 108.6s
=> exporting to image 2.0s
=> => exporting layers 2.0s
=> => writing image sha256:8326a9eb4706b6687c5b1329426b81e 0.0s
=>