Cheat sheet of important Docker commands

Search for a command to run...

No comments yet. Be the first to comment.
A strange problem showed up while I fixed storage in Kubernetes. The whole thing made little sense at first. I was trying to make an existing PersistentVolumeClaim (PVC) work with ReadWriteMany (RWX)

This is the continue of https://hashnode.com/post/cm8v7ntxi000209kw2xpm2tp7 To help you further understand Azure networking, let’s walk through a practical example of creating Virtual Machines (VMs), Network Security Groups (NSGs), and configuring ne...
Microsoft Azure offers Azure Virtual Network (VNet) as its core networking service, enabling users to create private, secure, and scalable cloud networks. Whether you're setting up cloud-only applications or hybrid architectures, understanding VNets ...

What is an Init Container? As Kubernetes pods can have more than one container.Init containers are specialized containers that run before app containers in a Kubernetes Pod. Unlike regular containers, init containers must complete successfully before...

Mocking means replacing real objects with pretend ones during testing, especially in unit tests. This technique lets to create different scenarios without using real resources, which saves time and effort. The Mock() object from the unittest.mock cla...

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.
The docker version displays the installed versions of the Docker, Nothing more than that.
docker version
"docker search" finds and displays relevant Docker images from registries, helping you discover and choose base containers for your applications.
docker search nginx
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
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
Gracefully stop a running container.
docker stop <container>
Remove one or more stopped containers.
docker rm <container>
List available Docker images on your system.
docker images
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
Build a Docker image from a Docker file.
docker build <path/to/Dockerfile>
Start containers defined in a Docker Compose file.
docker-compose up
Stop and remove containers defined in a Docker Compose file.
docker-compose down
List Docker networks on your system.
docker network ls
Display real-time resource usage statistics of running containers.
docker stats
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!