5
请教大家一个 docker 镜像制作相关问题
source link: https://www.v2ex.com/t/794338
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
工作中最近用到 docker,今天看了一天网上的教程看网上的教程 https://www.runoob.com/docker/docker-dockerfile.html
注意:Dockerfile 的指令每执行一次都会在 docker 上新建一层。所以过多无意义的层,会造成镜像膨胀过大。例如:
FROM centos
RUN yum install wget
RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz"
RUN tar -xvf redis.tar.gz
以上执行会创建 3 层镜像。可简化为以下格式:
FROM centos
RUN yum install wget \
&& wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \
&& tar -xvf redis.tar.gz
这里我试了这两种写法,docker 镜像的大小一样,这里制作 docker 镜像这两种写法有没有区别? centos:v3 是 3 个 run 生成的,v4 是第二种写法生成的。
[root Dockerfile]#docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v4 ede9b36dd800 8 seconds ago 260MB
centos v3 6df19efb1980 3 minutes ago 260MB
nginx v3 3ca44131eb70 6 hours ago 133MB
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK