Instruction commands in Docker

Last updated on May 27 2022
Raigiri Patil

Table of Contents

Instruction commands in Docker

Docker – Instruction Commands

Docker has a host of instruction commands. These are commands that are put within  the Docker File. Let’s look at the ones which are available.

CMD Instruction

This command is used to execute a command at runtime when the container is executed.

Syntax

CMD command param1

Options

  • command − This is the command to run when the container is launched.
  • param1 − This is the parameter entered to the command.

Return Value

The command will execute accordingly.

Example

In our example, we’ll enter a simple Hello World echo in our Docker File and create an image and launch a container from it.

Step 1 − Build the Docker File with the subsequent commands −

FROM ubuntu MAINTAINER demousr@gmail.com CMD [“echo” , “hello world”]

Here, the CMD is just used to print hello world.

Page 1 Image 1 60
hello world

Step 2 − Build the image using the Docker build command.

Page 2 Image 2 54
build

Step 3 − Run a container from the image.

Page 2 Image 3 28
container

ENTRYPOINT

This command can also be used to execute commands at runtime for the container. But we can be more flexible with the ENTRYPOINT command.

Syntax

ENTRYPOINT command param1

Options

  • command − This is the command to run when the container is launched.
  • param1 − This is the parameter entered into the command.

Return Value

The command will execute accordingly.

Example

Let’s take a look at an example to understand more about ENTRYPOINT. In our example, we’ll enter a simple echo command in our Docker File and create an image and launch a container from it.

Step 1 − Build the Docker File with the subsequent commands −

FROM ubuntu MAINTAINER demousr@gmail.com ENTRYPOINT [“echo”]

Page 3 Image 4 28
entry point

Step 2 − Build the image using the Docker build command.

Page 3 Image 5 21
build image

Step 3 − Run a container from the image.

Page 3 Image 6 10
run container

ENV

This command is used to set environment variables in the container.

Syntax

ENV key value

Options

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

Return Value

The command will execute accordingly.

Example

In our example, we’ll enter a simple echo command in our Docker File and create an image and launch a container from it.

Step 1 − Build the Docker File with the subsequent commands −

FROM ubuntu MAINTAINER demousr@gmail.com ENV var1=Tutorial var2=point

Page 4 Image 7 15
echo

Step 2 − Build the image using the Docker build command.

Page 4 Image 8 2
docker build

Step 3 − Run a container from the image.

Page 4 Image 9 4
run

Step 4 − Finally, execute the env command to see the environment variables.

Page 5 Image 10 2
docker container

WORKDIR

This command is used to set the working directory of the container.

Syntax

WORKDIR dirname

Options

  • dirname − The new working directory. If the directory doesn’t exist, it’ll be added.

Return Value

The command will execute accordingly.

Example

In our example, we’ll enter a simple echo command in our Docker File and create an image and launch a container from it.

Step 1 − Build the Docker File with the subsequent commands −

FROM ubuntu MAINTAINER demousr@gmail.com WORKDIR /newtemp CMD pwd

Page 6 Image 11 4
dockerfile

Step 2 − Build the image using the Docker build command.

Page 6 Image 12 1
docker build command

Step 3 − Run a container from the image.

Page 6 Image 13 1
run from container

So, this brings us to the end of blog. This Tecklearn ‘Instruction commands in Docker’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

 

0 responses on "Instruction commands in Docker"

Leave a Message

Your email address will not be published. Required fields are marked *