Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views6 pages

Dockerfile Instructions GHH

Uploaded by

psamanta1401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Dockerfile Instructions GHH

Uploaded by

psamanta1401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Dockerfile Instructions with Examples and Explanations

Dockerfile is used to build custom images. We can make use of docker instructions to create custom
images

It is a declarative way of custom images

Docker instructions are as follows,

1. FROM
The FROM instruction specifies the base image for your Docker image. It is the first instruction in the
Dockerfile and forms the foundation of your custom image.

Syntax: FROM <base-image>:<version>

Example:

2.

The RUN instruction is used to execute commands in the image during the build process. It’s often used
to install software or configure the environment.

Syntax: RUN <command>

Example:
3.
The CMD instruction specifies the default command that will be run when a container is created
from the image. Unlike RUN, it is executed at container runtime, not during image build.

Syntax: CMD ["executable", "param1", "param2"]

Example:

4.
The ENTRYPOINT instruction is similar to CMD but is generally used for scripts or commands that
must always be executed. It allows you to configure a container that will run as an executable.

Syntax: ENTRYPOINT ["executable", "param1", "param2"]

Example:
5.
The COPY instruction copies files from the host machine to the Docker image.

Syntax: COPY <source> <destination>

Example:

6.
The ADD instruction is similar to COPY, but it has additional features. It can extract archives and
fetch files from remote URLs.

It has two extra capabilities


1. Can download files directly from internet
2. Can untar directly into image

Syntax: ADD <source> <destination>

Example:
7.
The LABEL instruction adds metadata to the image in key-value pairs, which can be used for
descriptive or filtering purposes.

Syntax: LABEL <key>=<value>

Example:

8.
The EXPOSE instruction informs Docker that the container will listen on specific network ports,
though it does not actually publish the port to the host.

Syntax: EXPOSE <port>

Example:

9.
The ENV instruction sets environment variables in the container that can be accessed by
applications running inside the container.

Syntax: ENV <key>=<value>

Example:
10.
The WORKDIR instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT,
and other instructions.

Syntax: WORKDIR /path/to/workdir

Example:

11.
The ARG instruction defines build-time variables that can be passed to Docker during the build
process.

Syntax: ARG <name>=<default-value>

Example:

12.
The USER instruction sets the user to run subsequent commands during build or container
execution, improving security by avoiding root usage.

Syntax: USER <username>[:<group>]

Example:
13.
The ONBUILD instruction sets up a trigger that executes when the image is used as the base for
another build. It is commonly used in base images to specify additional actions for future
Dockerfiles.

Syntax: ONBUILD <INSTRUCTION>

Example:

You might also like