7/9/24About 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 committo 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 command
- MAINTAINER: the maintainer's info, name and email
- RUN: execute commands during building docker image
 SHELL:- RUN yum install vim
 EXEC:- RUN ["execute file", "param1", "param2"]
- EXPOSE: Expose port to outside
- WORKDIR: Specify the working directory after creating a container.
- USER: Specify the user need to execute, default is root
- ENV: Setup the environment variables during building.- ENV MY_PATH /root
- VOLUME: Container volume
- ADD: copy host file to docker, the url can be processed automatically, and tar file will be decompressed automatically also.
- COPY: copy host file to docker
- CMD: Specify the commands that need to be executed after run a container.
 ::: notes
 The- CMDcan 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 thecommandswill be the parameters to the script and specified byENTRYPOINT.
 
