Skip to content
Related Articles
Open in App
Not now

Related Articles

Docker – Instruction Commands

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 22 Oct, 2022
Improve Article
Save Article

Pre-requisite: Docker

Docker is an open-source project that automates the deployment of applications as movable, independent containers that can run locally or in the cloud. You can divide your applications from your infrastructure with the help of Docker, allowing for quick software delivery and it also allows you to manage your infrastructure in the same ways that you manage your applications.

 The number of commands found in docker is very huge in number, but we will be looking at the top commands in docker.

Docker Commands:

1. docker run: This command is used to run a container from an image.

$ docker run <name_of_the_container>
docker run image


2. docker pull: This command allows you to pull any image which is present at the official registry of docker, Docker hub. By default, it pulls the latest image, but you can also mention the version of the image.

$ docker pull <image_name>
Redis image latest version


3. docker ps: This command (by default) shows us a list of all the running containers. We can use various flags with it.

  • -a flag:  shows us all the containers, stopped or running.
  • -l flag: shows us the latest container.
  • -q flag: shows only the Id of the containers. 
$ docker ps [options..]
Running Containers


4. docker stop: This command allows you to stop a container if it has crashed or you want to switch to another one.

$ docker stop <container_ID>
docker stop image


5. docker start: Suppose you want to start the stopped container again, you can do it with the help of this command.

$ docker start <container_ID>
docker start image


6. docker rm: To delete a container. By default when we a container is created, it gets an ID as well as an imaginary name such as confident_boyd, heuristic_villani, etc. You can either mention the container name or its ID.

Some important flags:

  • -f flag: remove the container forcefully.
  • -v flag: remove the volumes.
  • -l flag: remove the specific link mentioned.
$ docker rm {options} <container_name or ID>
docker remove an image


7. docker images: Lists all the pulled images which are present in our system.

$ docker images
docker images metadata


8. docker exec: This command allows us to run new commands in a running container. This command only works until the container is running, after the container restarts, this command does not restart.

Some important flags:

  • -d flag: for running the commands in the background.
  • -i flag: it will keep STDIN open even when not attached.
  • -e flag: sets the environment variables 
$ docker exec {options}

ubuntu container


exec command


9. docker ports (port mapping): In order to access the docker container from the outside world, we have to map the port on our host( Our laptop for example), to the port on the container. This is where port mapping comes into play.

$ docker run -d -p <port_on_host> 
<port_on_container> Container_name
port 8080 on the host is mapped to container


So these were the 9 most basic docker commands that every beginner must know. Containerization is a very vast topic but you can start from the very basic commands and by practicing them daily you can master them.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!