Best practices for writing Dockerfiles | Docker image file
Thistopiccoversrecommendedbestpracticesandmethodsforbuildingefficientimages.DockerbuildsimagesautomaticallybyreadingtheinstructionsfromaDockerfile--atextfilethatcontainsallcommands,inorder,neededtobuildagivenimage.ADockerfileadherestoaspecificformatandsetofinstructionswhichyoucanfindatDockerfilereference[1].ADockerimageconsistsofread-onlylayerseachofwhichrepresentsaDockerfileinstruction.Thelayersarestackedandeachoneisadeltaofthechangesfromthepreviouslayer.Thefollowingisthecontentsofanexample...
This topic covers recommended best practices and methods for building efficient images.
Docker builds images automatically by reading the instructions from a Dockerfile -- a text file that contains all commands, in order, needed to build a given image. A Dockerfile adheres to a specific format and set of instructions which you can find at Dockerfile reference[1].
A Docker image consists of read-only layers each of which represents a Dockerfile instruction. The layers are stacked and each one is a delta of the changes from the previous layer. The following is the contents of an example Dockerfile:
# syntax=docker/dockerfile:1 FROM ubuntu:18.04 COPY . /app RUN make /app CMD python /app/app.pyEach instruction creates one layer:
FROM creates a layer from the ubuntu:18.04 Docker image. COPY adds files from your Docker client’s current directory. RUN builds your application with make. CMD specifies what command to run with...