DEV Community

Cover image for List of important Docker commands: Docker Series 03
Ankur Singh
Ankur Singh

Posted on

List of important Docker commands: Docker Series 03

Introduction

Welcome πŸ‘‹ to this blog. If you want to learn about Docker and are a beginner, you have come to the right place. This blog series will cover everything from the very beginning to the end. This blog will teach us about the necessary and important Docker commands.

List of commands

List the containers that are actively running

$ docker ps
Enter fullscreen mode Exit fullscreen mode

Note: If the Docker commands are not running in your system, it is not installed or does not have enough privileges to use it with sudo commands.

List all the containers irrespective of their running status

$ docker ps -all
Enter fullscreen mode Exit fullscreen mode

Run a Docker container

Step 1: Create a container

$ docker container create hello-world:linux
Enter fullscreen mode Exit fullscreen mode

Here, hello-world:linux is a hello world container image which is pulled from the docker hub

Step 2: Start the container

$ docker container start <Container ID>
Enter fullscreen mode Exit fullscreen mode

Here, is the container ID which can be obtained by running the previous commands docker ps.

Running the Docker container(short way)

$ docker run hello-world:linux
Enter fullscreen mode Exit fullscreen mode

docker run = docker container create + docker container start + docker container attach

Getting the log of the container

$ docker log <Container ID>
Enter fullscreen mode Exit fullscreen mode

Run additional commands from the container

$ docker exec <Conatiner ID> <Commands>
Enter fullscreen mode Exit fullscreen mode

Starting a interactive shell

$ docker exec --interactive --tty <Container ID>
Enter fullscreen mode Exit fullscreen mode

Stop the container immediately

$ docker stop -t <ID>
Enter fullscreen mode Exit fullscreen mode

Remove the container

$ docker rm <Container ID>
Enter fullscreen mode Exit fullscreen mode

List all the docker image

$ docker images
Enter fullscreen mode Exit fullscreen mode

Remove the Docker image

$ docker rmi <Image ID>
Enter fullscreen mode Exit fullscreen mode

Remove the Docker Image forcefully

$ docker rmi -f <Image ID>
Enter fullscreen mode Exit fullscreen mode

Binding ports to the container

$ docker run -p 5001:5000 our-server
Enter fullscreen mode Exit fullscreen mode

Tagging the image name

$ docker tag <Local-image-name> username/your-image-name:0.0.01
Enter fullscreen mode Exit fullscreen mode

Conclusion

In this blog, we explored different commands of Docker containers, images, emphasising their roles in container & image creation. In the next blog, we will delve deeper into the technical aspects. Stay tuned

Hire me: [email protected]
LinkedIn
Twitter

Top comments (0)