Top 10 Docker Commands You Should Know!

Filed Under: Random
Docker Commands

Hey, readers! In this article, we will be focusing on 10 Docker Commands that are mostly in use!

So, let us begin! 馃檪

Efficiency of Docker commands

Docker provides us an efficient way to pack our applications and its dependencies into a single unit, representing it into a Container. Yes, a Container contains all the application specific data and its environment specific data.

For the same, once we have the application up in the container, we can introspect it and also perform various monitoring and inspections with it using docker commands.

List of commands to know!

Let us go through some of the most used docker commands now.

1. Docker Process

We can list all the current running processes using the below command. It would list all the current running processes i.e. containers.

docker ps

But, in case we want to list all the processes irrespective of its status i.e. active/exited, then the below command can help us-

docker ps -a -- all exited and live containers

With the above command, we can get a list of all the running as well as exited containers in Docker.

2. Stop a Docker container

With the below command, we can stop all the containers in docker. At first, with docker ps -aq, we list all the processes and then use stop command to exit them.

docker stop $(docker ps -aq)

3. Start a container

In order to start an exited container, use docker ps command to get the list of containers (which includes the container ID). Further, use docker start command to start the exited container.

docker start <CONTAINER_ID>

4. Stop a specific running container

At step 2, we saw a command that enables us to stop all the containers. But what if we wish to stop a single/specific container? In this case, we use the below command to stop a particular container using its container ID.

docker stop <container_id>

5. Remove an image

We can remove all the layers of the docker image built from Dockerfile using the below command–

docker rmi <IMAGE_ID> -f

With docker rmi command, we remove the image using its image ID with all the existing layers of it.

6. Build an Image

In order to have an application up and running within containers, it demands for Image. Thus, we make use of the below command to build a Docker Image using the Dockerfile.

docker build -t anyname .

7. Get inside the docker container

Once the application is up and running within a container, we often come across scenarios wherein we feel the need to check the data that gets printed within the container. For the same purpose, we can get inside a container using the below command–

docker exec -it <CONTAINER_ID_OR_NAME> bash

Instead of bash, we can also have sh. Upon execution of the command, a terminal opens into which we can apply different commands to check the data stored.

8. Tag a Docker Image

Prior to pushing the docker image into some public or private registry, we can tag the image using the below command–

docker tag <<IMAGE_ID or IMAGE_NAME>> mynodejs:v1 

Tagging images enables us to have the latest version of images and helps us distinguish between different versions of images.

9. Run a docker image

Using -it i.e. interactive mode, we can directly run an image as a docker container with the below command–

docker run -it image-name powershell

10. Run wordpress locally at fingertips

Yes, at first, we pull the base wordpress image from docker hub using docker pull command.

Further, we check if the image has been locally stored using docker images command.

Then, we run the docker image of wordpress locally using docker run command. Here -p refers to the port on which we would run the wordpress locally. We would be running it on port 80 i.e. http.

Finally, visit http://localhost to view the wordpress running locally on your workstation.

docker pull tutum/wordpress

docker images

docker run -d -p 8080:80 tutum/wordpress

go to http://localhost or http://localhost:8080 to view


By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.

For more such posts related to Docker and Kubernetes, Stay tuned with us.

Till then, Happy Learning!! 馃檪

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors