Dockerfile in depth
Table of contents:
Chain RUN instructions
- each RUN command will execute the command on top writable layer of the container, then commit the container as a new image
- the new image is used for the next step in the Dockerfile. So each RUN instructions will create a new image layer
- it is recommended to chain the RUN instructions in the Dockerfile to reduce the number of image layers it creates
Example
Bellow we have a simple Dockerfile. We can modify the Dockerfile:
FROM debian:jessie
RUN apt-get update
RUN apt-get install -y git
RUN apt-get intall -y vim
instead of 4 lines we can agregate lines to get more cosins chain, like:
FROM debian:jessie
RUN apt-get update && apt-get install -y \
git \
vim
When building a docker image we have two steps instead of three:
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM debian:jessie
---> 3aaeab7a4777
Step 2/2 : RUN apt-get update && apt-get install -y git vim
---> Running in c628f9060664
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [16.3 kB]
Get:3 http://deb.debian.org jessie Release.gpg [1652 B]
Instructions
Fundamental Instructions:
- FROM
- ARG
Configuration Instructions:
- RUN
- ADD
- COPY
- ENV
Execution Instructions:
- CMD
- ENTRYPOINT
- EXPOSE
Reference:
My site is free of ads and trackers. Was this post helpful to you? Why not
Disqus is great for comments/feedback but I had no idea it came with these gaudy ads.