Working with Docker | Top 20 Docker Commands
Docker has become an integral part of software engineering. We use Docker for development, testing, and deployment because it’s easy to manage the environment. Because of its portability, it has become popular in the software industry. That means if your code works in development, it will work in production. Moreover, developers can collaborate faster without worrying about which software dependency to install.
In our previous blogs, I have covered What Docker is and how we can use it. Today, in this blog, I will talk about the Top 20 Docker Commands that you will frequently use while working with Docker.
You can find the official documentation for these commands on Docker’s documentation page.
Idea:
A guide to the top 20 Docker commands for working with Docker.
Outline:
- What is Docker commands?
- What are the benefits of using Docker commands?
- What are the top 20 Docker commands for working with Docker?
1.What is Docker commands?
Docker commands are the commands used to manage Docker containers. They can be used to create, start, stop, and delete containers and get information about them.
2.What are the benefits of using Docker commands?
Docker is a containerization tool that allows developers to create, deploy, and run applications within a container. Using Docker commands can help you speed up these processes and make them more efficient.
Some of the benefits of using Docker commands include the following:
- You can automate the process of creating and deploying your applications.
- You can manage your applications more effectively.
- You can control your environment more effectively.
- You can improve your workflow.
- You can speed up the process of deploying and managing your applications.
3.What are the top 20 Docker commands for working with Docker?
1. docker version
docker –version
This command will print out the version of Docker that you have installed.
sudo docker pull <image name>
This command is used to pull images from a Docker repository(hub.docker.com)
For example, to pull the latest version of the ubuntu image, you would run the following:
sudo docker pull ubuntu
3. docker images
sudo docker images
The command outputs a list of all downloaded images on your machine. In our case, it is a Ubuntu with image details such as TAG/IMAGE ID/SIZE, etc.
sudo docker login
This command helps you to log into your docker hub. As you try to log in, you will be asked to give your docker hub credentials, such as username and password.
sudo docker push <username/image name>
docker push is the command you’ll use to push an image to the docker hub repository. It is a key part of the deployment process, and you will need to use it with the docker tag and docker login to work properly.
docker run -it -d <image name>
This command is used to create a container from an image.
sudo docker ps
This command is used to list the running containers
sudo docker ps –a
This command shows all the docker containers running, exited, and stopped with container details.
sudo docker exec -it <container id> bash
This command is used to access the docker container and run commands inside the container.
The -i and -t options are used to access the container in an interactive mode. Then we provide the container id we want to access. Finally, the bash command gets a bash shell inside the container.
sudo docker stop <container id>
This command is used to stop a running container. You can specify the container by name or ID.
sudo docker ps
sudo docker start <container id>
This command is used to start a running container. You can specify the container by name or ID.
sudo docker ps
docker commit <container id> <username/image name>
This command is used to create or save an image of the edited container on the local system.
sudo docker info
This command is used to get detailed information about the docker installed on the system, including the server version, the number of stopped containers and images running, etc.
14. docker network
sudo docker network ls
This command is used to get docker lists of the details of all the networks in the cluster.
sudo docker build <path to docker file>
The docker build command is used to create a new Docker image from a given Dockerfile. The command takes a path to a Dockerfile and builds an image based on the instructions contained in the file.
sudo docker rename <old container name> <new container name>
This command is used to change the container name from peaceful_shirley to ubuntu_container. We can change the name to keep track of our containers more easily.
sudo docker kill < container id >
This command is used to kill the container by stopping its execution immediately. And the difference between ‘docker kill’ and ‘docker stop’ is that the ‘docker stop’ command stops the container gracefully. That’s the difference between kill and stop commands.
sudo docker rm <container id>
This command is used to remove or delete a stopped container. You can specify the container by name or ID.
sudo docker rmi <image-id>
This command is used to remove or delete an image from local storage. You can specify the image by name or ID.
sudo docker logout
This command is used for logging you out of the docker hub.
Summary:
Docker commands are the commands used to manage Docker containers. They can be used to create, start, stop, and delete containers and get information about them. This blog explains 20 docker commands that will help you get started with docker and learn to perform basic functions without getting overwhelmed.