If anything missed kindly add in comment
- A sequential set of instruction for Docker engine , or a set of commands to assemble the an image
- Primary way of interacting with Docker and migrating containers.
- Each sequential instructions are processed individually and results are stored as stack of layers. This sequential layer managed by file system becomes a docker image.
- Sequential layers helps to cache and helps to troubleshoot.This precreated layer are reused by docker daemon when we run two docker file that has same layer at some stage.
Format:
ARG
FROM
RUN
ADD|COPY
ENV
CMD
ENTRYPOINT
EXPOSE
No extention required, can be created from any text editor, its good to start a docker file name with 'D' capital.
EXAMPLE:
ARG VERSION=16.04
FROM Ubuntu:${VERSION}
RUN apt-get update -y
CMD ["bash"]
Comments in Dockerfile is represented using '#'. But all hash preceeded sentence is not comments. That also means parser directive.
Parser directive
parser directive, one of the docker command indicates, how the docker file should be handled or read. It should be at the top of the file.
Types of parser:
syntax: Its only available in buildKit, but its used
to know the location of the dockerfile.escape: it available anywher, it used to specify the
character to escape. default is '\'.
COMMANDS:
- ARG is the only instruction that may precede FROM
- FROM can appear multiple times within a single Dockerfile to create multiple images or use one build stage as a dependency for another.
- WORKDIR This sets the working directory for Run, cmd, copy. By default the WORKDIR is created if not specified.
- RUN to execute any command in new layer on top of current layer RUN ["executable", "param1", "param2"]. (exec form) another way of executing command irrespective of the shell based. eg RUN ["/bin/bash", "-c", "echo hello"].
- ADD Add new files from src and copies to dest. used to copy to docker image. should be used with caution.
- COPY Copy new files from src to dest, used to copy to docker container.
- Env Provide value for environment variable
- CMD Used to execute command in shell docker file can contain only on CMD , if more than one specified last final will be executed.
- Entry point Used to execute command when container is initiated
- Expose expose a particular port with specific protocols
Top comments (0)