Docker Instruction Commands - Docker (software)

What are Docker - Instruction Commands?

The instruction commands are those in the Docker File and Docker has them. We will learn them in this chapter.

CMD Instruction

This runs a command during runtime when the execution is happening to the container.

Syntax

Options

  • command – this shows the command to be executed when we launch the container.
  • param1 – It is the command parameter.

Return Value

Mentioned command will execute.

Example

Let us echo simple Hello World to understand how this works and also the image creation and launching the container.

Step 1 – Give in the below commands in the Docker File –

We have written command to print simple hello world.

CMD

Step 2 – Next step is to build Docker image using build command.

build_command (1)

Step 3 – Finally, using Image let us Run a container.

run_a_container

ENTRYPOINT

Using above command the commands are run on container at runtime. Even then the command ENTRYPOINT is made to work easily.

Syntax

Options

  • command – The command that needs to be executed after launching the container.
  • param1 – The command takes the parameter and is mentioned.

Return Value

Mentioned command will execute.

Example

We will discuss more on how the ENTRYPOINT works. Let us echo simple to understand how this works and also the image creation and launching the container.

Step 1 − Give in the below commands in the Docker File –

entry_point (1)

Step 2 − Next step is to build Docker image using build command.

docker_build_command (1)

Step 3 − Finally, using Image let us Run a container.

container_from_image (1)

ENV

Environment variables can be set using ENV command.

Syntax

Options

  • Key − This is the key for the environment variable.
  • value − This is the value for the environment variable.

Return Value

Mentioned command will execute.

Example

Let us echo simple to understand how this works and also the image creation and launching the container.

Step 1 − Give in the below commands in the Docker File –

ENV

Step 2 − Next step is to build Docker image using build command.

env_docker_build_command

Step 3 − Then, using Image let us Run a container.

env_run_a_container

Step 4 − Lastly, to view the environment variables in the container run the env command.

env_command

WORKDIR

For setting up the workspace directory, WORKDIR command is used.

Syntax

Options

  • dirname – It is the name of the created directory. If not present earlier, it will be created and added.

Return Value

Mentioned command will execute.

Example

Let us echo simple to understand how this works and also the image creation and launching the container.

Step 1 − Give in the below commands in the Docker File –

workdir

Step 2 − Next step is to build Docker image using build command.

workdir_build_command

Step 3 − Then, using Image let us Run a container.

workdir_run_command

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Docker (software) Topics