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. 

Earn the Most Coveted DevOps Certification!

DevOps Engineer Masters ProgramExplore Program
Earn the Most Coveted DevOps Certification!

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. 

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

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!

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] 

    Elevate Your Tech Career!

    Docker Certified Associate Training CourseExplore Program
    Elevate Your Tech Career!
  • 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]

    Elevate Your Tech Career!

    Docker Certified Associate Training CourseExplore Program
    Elevate Your Tech Career!
  • 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.

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!

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.

Elevate Your Tech Career!

Docker Certified Associate Training CourseExplore Program
Elevate Your Tech Career!

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
  • Acknowledgement
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.