Cheat sheet of important Docker commands
3 min read
Before jumping into the topic, If you're new to Docker and looking for effective ways to manage Docker containers, you're in luck! Docker commands provide a solution to help you achieve just that.
Docker is a widely used platform that enables developers to package their applications, along with their dependencies and configurations, into containers that can seamlessly run across various environments.
With Docker commands, you gain the power to effortlessly create, run, stop, remove, and manage Docker containers. These commands prove to be invaluable in automating and streamlining the process of deploying and managing your applications within a containerized environment. By leveraging Docker commands, you can ensure a smooth and efficient workflow for your container-based applications.
You can easily visit the Docker Documentation for more information.
Docker version :
The docker version displays the installed versions of the Docker, Nothing more than that.
Docker search :
"docker search" finds and displays relevant Docker images from registries, helping you discover and choose base containers for your applications.
docker search nginx
Docker pull :
The "docker ps" command is valuable for efficiently checking the status and essential information of your active containers. It enables effective container monitoring and management, including tasks like identifying running containers, restarting or stopping specific containers, and inspecting their configurations.
To see the previously stopped containers use the option “-a”
sudo docker ps #you can user the command to get the images status sudo docker ps -a
Docker run :
Create and start a container from an image.
docker run <image>
To run a container in the background and regain control of the current terminal, use the "-d" option with the "docker run" command.
docker run -d <image_name>
To specify specific ports for Docker containers, use the "-p" option to map host ports to container ports, enabling communication between the host machine and the container.
docker run -p <host_port_number>:<container_port> <image_name>
To give the name to your container, use the option “ — name”.
docker run -p <host_port_number>:<container_port> <image_name> --name docker-image
Docker stop :
Gracefully stop a running container.
docker stop <container>
Docker rm :
Remove one or more stopped containers.
docker rm <container>
Docker images :
List available Docker images on your system.
Docker rmi :
It is used to remove one or more Docker images from your system. You need to stop the running container to delete the image.
docker rmi <image1> <image2> <image3> or, docker image prune -a
Docker build :
Build a Docker image from a Docker file.
docker build <path/to/Dockerfile>
Docker-compose up :
Start containers defined in a Docker Compose file.
Docker-compose down :
Stop and remove containers defined in a Docker Compose file.
Docker network ls :
List Docker networks on your system.
docker network ls
Docker stats :
Display real-time resource usage statistics of running containers.
Docker Logs :
Display the logs of a specific container
docker logs <container>
And with that, we've covered the majority of the important commands in this post. If there are any commands I missed, feel free to mention them in the comments. That concludes our discussion for now. Happy Dockerizing!