List of dockerfile instructions and its Brief Summary?

The format of Dockerfile is similar to the below syntax:

# Comment

INSTRUCTION arguments

A Dockerfile must start with a FROM instruction.

There are multiple INSTRUCTIONS that are available in Dockerfile, some of these include:

  • FROM
  • RUN
  • CMD
  • LABEL
  • EXPOSE

FROM: The FROM instruction specifies the Base Image from which you are building.

RUN: In this we can run our commands for installing the packages

ADD: This instruction will give the output of converting tar file in to normal file and it will add in to that particular directory.

COPY: This instruction will give the output of copying the content and nothing will do more than that in the docker instruction. This instruction will give you the result of moving files.

COPY and ADD are both Dockerfile instructions that serve similar purposes. They let you copy files from a specific location into a Docker image.

EXPOSE: The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

HEALTHCHECK: The HEALTHCHECK instruction Docker allows us to tell the platform on how to test that our application is healthy. When Docker starts a container, it monitors the process that the container runs. If the process ends, the container exits.  That’s just a basic check and does not necessarily tell the detail about the application.

We can specify certain options before the CMD operation, these includes:

HEALTHCHECK –interval=5s CMD ping -c 1 172.17.0.2

  • –interval=DURATION (default: 30s)
  • –timeout=DURATION (default: 30s)
  • –start-period=DURATION (default: 0s)
  • –retries=N (default: 3)

ENTRYPOINT: The best use for ENTRYPOINT is to set the image’s main command. This doesn’t allow you to override the command. It is important to understand the distinction between CMD and ENTRYPOINT

Sample Code Snippet:

FROM ubuntu

ENTRYPOINT [“top”, “-b”]

CMD [“-c”]

WORKDIR: The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.The WORKDIR instruction can be used multiple times in a Dockerfile.

ENV: The ENV instruction sets the environment variable <key> to the value <value>.

You can use -e, –env, and –env-file flags to set simple environment variables in the container you’re running or overwrite variables that are defined in the Dockerfile of the image you’re running.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x