Docker has revolutionized how we build, ship, and run applications. Mastering Docker commands is essential for developers and DevOps professionals. Here’s a rundown of the most important Docker commands and how to use them effectively.

1. docker run

The docker run command creates and starts a container from a specified image. It’s the most basic command you’ll use to work with Docker containers.

docker run -it ubuntu

2. docker ps

The docker ps command lists all running containers. To see all containers, including stopped ones, add the -a flag.

docker ps
docker ps -a

3. docker images

The docker images command lists all images stored locally on your machine.

docker images

4. docker build

The docker build command builds an image from a Dockerfile.

docker build -t my-image:latest .

This command builds an image with the tag my-image:latest from the Dockerfile in the current directory.

5. docker pull

The docker pull command downloads an image from a Docker registry, such as Docker Hub.

docker pull nginx

This command pulls the latest NGINX image from Docker Hub.

6. docker push

The docker push command uploads an image to a Docker registry.

docker push my-image:latest

This command pushes my-image:latest to the configured registry.

7. docker exec

The docker exec command runs a command inside a running container.

docker exec -it my-container /bin/bash

This command opens an interactive terminal in the my-container container.

8. docker stop

The docker stop command stops a running container.

docker stop my-container

9. docker rm

The docker rm command removes a stopped container.

docker rm my-container

10. docker rmi

The docker rmi command removes an image from your local storage.

docker rmi my-image:latest

Mastering these Docker commands will enhance your ability to manage containers and streamline your development workflow. From running containers to managing images and interacting with registries, these commands are the foundation of effective Docker usage. Start integrating these commands into your daily tasks to leverage the full power of Docker.

The link has been copied!