Top Docker Commands Tutorial: All You Need to Know

The famous global researcher Gartner predicts that by 2023, more than 50 percent of companies will be adopting Docker containers in production. However, a serverless container like Docker will have the revenue from a small base of $465.8 million in 2020, to reach $944 million in 2024.

That was all about the demand for Docker in the market.

In this tutorial, we will be discussing the Top Docker Commands that a developer uses frequently while working with the Docker tool. 

What Is Docker?

Docker is a configuration management tool that helps a developer to wrap an application and its dependencies into a Docker Container for the development and deployment of software.

Moving forward, let’s discuss the top Docker commands that are widely used by the developers. 

FREE DevOps Certification Training

Master the fundamentals of DevOpsStart Learning
FREE DevOps Certification Training

List of Docker Commands

  • Build an image from the Dockerfile in the current directory and tag the image 

docker build -t myimage:1.0 

List all Docker images

docker images

docker-images-command

Delete an image from the docker image

docker image rm alpine:3.4

Container Commands

Mentioned below are the necessary commands for working with Docker container images.

  • Create a container

docker create [IMAGE] 

  • Run a command in a new container

docker run [IMAGE] [COMMAND] 

  • Rename an existing container

docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME]

  • Removes all the stopped containers

docker container prune [OPTIONS] 

  • Create a new image from a container’s file changes

docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

  • Remove an existing container

docker rm [CONTAINER] 

  • List the running containers

docker container ls

running-container-command

  • Stop a running container

docker stop [CONTAINER_NAME]

  • Restart a running container

docker restart [CONTAINER]

  • Kill the running containers

docker Kill [CONTAINER]

docker-kill-command.

  • Attach local standard input, output, and error streams to a running container

docker attach  [CONTAINER]

attach-container

  • Block a container 

docker wait  [CONTAINER]

docker-wait-command

Docker Share Command

The following commands show how to share command in Docker.

  • Pull an image from a registry

docker pull [OPTIONS] NAME[:TAG] 

docker-pull-command

  • Push an image to a registry 

docker push [OPTIONS] NAME[:TAG] 

  • Run a command in a running container

docker exec [OPTIONS] CONTAINER COMMAND [ARG...] 

General Commands

The following code shows the general command in Docker.

  • Login into docker hub

docker login 

docker-login-command

  • Get information on the Docker tool

docker info

  • Display the history of an image with the image name mentioned in the command

docker history httpd 

history-command

  • Create a volume for containers

docker volume create

volume-commands.

Docker Swarm Commands

Below you will find all the frequently used Docker Swarm commands.

  • Create a Docker Swarm

docker swarm init --advertise-addr [IP ADDRESS] 

  • Joins nodes in the swarm

docker swarm join --advertise-addr HOST:PORT 

  • Execute this command to leave docker swarm

docker swarm leave [OPTIONS]

Docker Compose Commands

Below you will find all the frequently used Docker Compose commands.

  • Display docker-compose version

docker-compose -version 

compose-commands

  • Creating your first Docker-Compose File

vi docker-compose.yml

vi-commands

  • Run our Docker Compose file

docker-compose up 

Enroll for the Docker Certified Associate Training Course to learn the core Docker technologies like the Docker Containers, Docker Compose, and more.

Conclusion

That was all the basics about Docker Commands.

If you are interested in gaining in-depth knowledge of the Docker tool, Simplilearn can definitely help you. The Docker In-Depth Training Course will help you learn all the basic and advanced concepts of Docker. With this certification, you will gain hands-on experience on how to create flexible application environments with Docker.

Do you have any doubts about this topic? Please feel free to place your questions in the comments section of this Docker Commands tutorial and our experts will get back to you at the earliest!

About the Author

Sana AfreenSana Afreen

Sana Afreen is a Senior Research Analyst at Simplilearn and works on several latest technologies. She holds a degree in B. Tech Computer Science. She has also achieved certification in Advanced SEO. Sana likes to explore new places for their cultures, traditions, and cuisines.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.