04. Dockerfile
July 9, 2024About 1 min
Dockerfile Basic
Basic Rules
- Every reserved words command need to use upper case and follow at least one argument
- The commands are executed from top to bottom as order.
#
means comment- Every command will create a image layer to commit to final image.
How the docker parse Dockerfile
- docker to run a container from a basic image
- execute a command to modify container
- execute a command similar with
docker commit
to commit a new image layer. - docker to run a container based on the commited image.
- execute the next command untill finish all the commands.
Reserved Words
FROM
: specify the basic image as template, normally it's the first commandMAINTAINER
: the maintainer's info, name and emailRUN
: execute commands during building docker image
SHELL:RUN yum install vim
EXEC:RUN ["execute file", "param1", "param2"]
EXPOSE
: Expose port to outsideWORKDIR
: Specify the working directory after creating a container.USER
: Specify the user need to execute, default is rootENV
: Setup the environment variables during building.ENV MY_PATH /root
VOLUME
: Container volumeADD
: copy host file to docker, the url can be processed automatically, and tar file will be decompressed automatically also.COPY
: copy host file to dockerCMD
: Specify the commands that need to be executed after run a container.
::: notes
TheCMD
can appear multiple times, but only the last one is valid. And it will be replaced by docker run command
:::ENTRYPOINT
:- To specify a command when a container startup.
- Similar with
CMD
, but it can not be overwritten by docker runcommands
, and thecommands
will be the parameters to the script and specified byENTRYPOINT
.