Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 15, 2022 09:17 am GMT

What is Dockerfile ? (Docker Series - III)

  1. A sequential set of instruction for Docker engine , or a set of commands to assemble the an image
  2. Primary way of interacting with Docker and migrating containers.
  3. 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.
  4. 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:

ARGFROMRUNADD|COPYENVCMDENTRYPOINTEXPOSE

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.04FROM Ubuntu:${VERSION}RUN apt-get update -yCMD ["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:

  1. syntax: Its only available in buildKit, but its used
    to know the location of the dockerfile.

  2. escape: it available anywher, it used to specify the
    character to escape. default is '\'.

COMMANDS:

  1. ARG is the only instruction that may precede FROM
  2. FROM can appear multiple times within a single Dockerfile to create multiple images or use one build stage as a dependency for another.
  3. RUN to execute any command in new layer on top of current layer RUN "executable", "param1", "param2" another way of executing command irrespective of the shell based. eg RUN ["/bin/bash", "-c", "echo hello"].
  4. ADD Add new files from src and copies to dest. used to copy to docker image. should be used with caution.4b. COPY Copy new files from src to dest, used to copy to docker container.
  5. Env Provide value for environment variable
  6. CMD Used to execute command in shelldocker file can contain only on CMD , if more than one specified last final will be executed.
  7. Entry point Used to execute command when container is initiated
  8. Expose expose a particular port with specific protocols

Original Link: https://dev.to/bhargavirengarajan21/what-is-dockerfile-docker-series-iii-35ai

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To