What is Docker?
Docker has become one of the most popular tools for developers, DevOps engineers, and system administrators. It allows applications to run in lightweight, portable containers, making deployment easier and more consistent across different environments. Whether you are new to Docker or have been using it for a while, knowing the essential Docker commands can save you time and make your workflow more efficient.
Top Docker Commands Every Developer Should Know
In this article, we’ll go through the top Docker commands you should know, along with explanations and practical examples.
1. docker –version
The simplest command, but an important one. This checks the Docker version installed on your machine.
docker --version
Useful when troubleshooting compatibility issues or verifying an installation.
2. docker pull
This command downloads a Docker image from Docker Hub (or any other registry).
docker pull nginx
For example, the above command pulls the latest Nginx image.
3. docker images
Lists all the images stored on your system.
docker images
You can see the repository name, tag, image ID, and size.
4. docker run
The most commonly used command. It creates and runs a container from an image.
docker run -d -p 8080:80 nginx
Here, -d runs it in detached mode and -p maps port 8080 on your machine to port 80 inside the container.
5. docker ps
Shows all running containers.
docker ps
If you want to see stopped containers as well, use:
docker ps -a
6. docker stop
Stops a running container by its ID or name.
docker stop <container_id>
7. docker rm
Removes a stopped container.
docker rm <container_id>
You can also remove multiple containers at once by listing IDs.
8. docker rmi
Deletes an image from your local system.
docker rmi <image_id>
9. docker exec
Used to run commands inside a running container.
docker exec -it <container_id> bash
This opens an interactive shell inside the container.
10. docker logs
Displays logs from a container.
docker logs <container_id>
Helpful for debugging applications inside containers.
11. docker build
Builds a Docker image from a Dockerfile.
docker build -t myapp:1.0 .
Here, -t tags the image, and . points to the Dockerfile in the current directory.
12. docker-compose up
If you’re working with Docker Compose, this command starts all services defined in your docker-compose.yml file.
docker-compose up -d
The -d flag runs services in the background.
Final Thoughts
Docker is a powerful tool, but it can feel overwhelming at first. By mastering these top Docker commands, you’ll streamline your container management and make your development process much smoother.
If you’re new, start with docker run, docker ps, and docker exec. As you grow more comfortable, explore advanced commands like docker build and docker-compose.
By bookmarking this list and practicing regularly, you’ll be well on your way to becoming confident with Docker.
