DEV Community

Palak Bhawsar
Palak Bhawsar

Posted on • Originally published at palak-bhawsar.hashnode.dev on

20 Useful Docker Commands

Hey there! I am Palak. I like writing technical blogs and sharing my knowledge with the community. I am passionate about Cloud & DevOps. I am writing this blog to share the Docker commands that I mostly use.

Docker was released as an open-source project in 2013. Docker enables developers to easily pack, ship, and run any application as a lightweight, portable, self-sufficient container, which can run anywhere. Docker is an application that simplifies the process of managing application processes in containers.

Containers let you run your applications in resource-isolated processes. Theyre similar to virtual machines, but containers are more portable, more resource-friendly, and more dependent on the host operating system.

So, let's get started.

Docker version

This command is used to find a version of Docker

docker --version

Enter fullscreen mode Exit fullscreen mode

List docker containers

This command list the running containers

docker ps

Enter fullscreen mode Exit fullscreen mode

List all docker containers

This command lists all the running and exited containers

docker ps -a

Enter fullscreen mode Exit fullscreen mode

List docker Images

This command lists all the locally stored docker images

docker images

Enter fullscreen mode Exit fullscreen mode

Start container

This command is used to start a container that has been stopped

docker start <container id>

Enter fullscreen mode Exit fullscreen mode

Stop container

This command stops a running container

docker stop <container id>

Enter fullscreen mode Exit fullscreen mode

Create docker image

This command creates a container from an image

docker run <image name>

Enter fullscreen mode Exit fullscreen mode

Remove docker image

This command deletes an image from local storage

docker rmi <image id>

Enter fullscreen mode Exit fullscreen mode

Remove docker container

This command deletes a stopped container

docker rm <container id>

Enter fullscreen mode Exit fullscreen mode

Pull image

This command pulls images from the docker repository

docker pull <image name>

Enter fullscreen mode Exit fullscreen mode

Docker commit

This command creates a new image of an edited container

docker commit <container id> <username/image name>

Enter fullscreen mode Exit fullscreen mode

Access running container

This command is used to access the running container

docker exec <container id> cat /etc/os-release

Enter fullscreen mode Exit fullscreen mode

Push docker image

This command is used to push an image to the docker hub repository

docker push <username/image name>

Enter fullscreen mode Exit fullscreen mode

Inspect container

This command will list the complete information of the container

docker inspect <container id>

Enter fullscreen mode Exit fullscreen mode

Container Logs

This command will list the complete information of the container

docker logs <container-name or container-id>

Enter fullscreen mode Exit fullscreen mode

Restart docker container

This command is used to restart one or more containers

docker restart <container id>

Enter fullscreen mode Exit fullscreen mode

Login docker hub

This command is used to log in to the docker hub

docker login

Enter fullscreen mode Exit fullscreen mode

Kill container

This command is used to kill the container by stopping its execution

docker kill <container id>

Enter fullscreen mode Exit fullscreen mode

List processes of a container

This command is used to list the running processes of a container

docker top <container id>

Enter fullscreen mode Exit fullscreen mode

Live stream of container

This command is used to display a live stream of container resource usage statistics

docker stats <container id>

Enter fullscreen mode Exit fullscreen mode

Thank you for reading my blog. I hope you find it useful. If you enjoyed this post, feel free to follow me on Twitter πŸ‘©πŸ’»

Top comments (0)