Essential Docker Commands: A Quick Reference

User Icon By Azam Akram,   Calendar Icon April 3, 2025
Essential Docker Commands

Docker is a powerful tool for containerization, and knowing the right commands can significantly improve your workflow. Below is a list of commonly used Docker commands along with their descriptions and examples.

You can find many useful docker related blogs here.

Basic Commands

1. Check Docker Version

docker --version

Displays the installed Docker version.

2. Log in to Docker Hub

docker login

Authenticates you to Docker Hub.

3. Log out from Docker Hub

docker logout

Logs you out from Docker Hub.

Image Management

4. List Docker Images

docker images

Displays all locally available Docker images.

5. Pull an Image from Docker Hub

docker pull <image_name>

Downloads a Docker image from Docker Hub.

6. Remove an Image

docker rmi <image_id>

Deletes a specific Docker image from your local machine.

7. Tag an Image

docker tag <image_id> <repository>:<tag>

Assigns a tag to an existing image.

Container Management

8. List Running Containers

docker ps

Displays all active containers.

9. List All Containers (including stopped ones)

docker ps -a

Shows all containers, running or stopped.

10. Run a Container

docker run <image_name>

Creates and starts a new container from an image.

11. Stop a Running Container

docker stop <container_id>

Stops a running container.

12. Restart a Container

docker restart <container_id>

Restarts a running or stopped container.

13. View Container Logs

docker logs <container_id>

Displays the logs of a running container.

14. Remove a Container

docker rm <container_id>

Deletes a stopped container.

Docker Compose Commands

15. Start Services Defined in docker-compose.yml

docker-compose up

Starts containers as defined in the docker-compose.yml file.

16. Stop and Remove Containers, Networks, and Volumes

docker-compose down

Stops and removes all resources created by docker-compose up.

17. List Running Compose Services

docker-compose ps

Shows the status of containers managed by Docker Compose.

Advanced Commands

18. Execute a Command Inside a Running Container

docker exec -it <container_id> <command>

Runs a command inside an active container.

19. Show Container Resource Usage

docker stats

Displays real-time resource usage statistics of running containers.

20. Show Container Processes

docker top <container_id>

Lists processes running inside a container.

21. Prune Unused Docker Resources

docker system prune

Removes unused containers, networks, and images to free up space.

By learning these Docker commands, you can effectively manage images, containers, and services. Whether you're just getting started with Docker or already an experienced user, keeping these commands handy will help streamline your workflow!