Basic Docker CLI Commands

Your Baby Steps Into Docker

Supun Sandaruwan
LinkIT
4 min readMar 4, 2021

--

In this article we will discuss the most basic and important Docker CLI commands you need to be aware of. Docker is a famous tool designed to make it easier to create, deploy, and run applications by using containers. I explained that introduction part in my first docker article. Containers are very important in application development, some data science activities, and security.

image from blog.knoldus.com

Docker Pull

This command is used to pull images from the docker repository (hub.docker.com).

docker pull
image from author

Docker Start

This will start an existing container.

docker start
image from author

Docker PS — Process Status

This command is used to show all the running and other existing containers.

image from author

This command is used to list the running containers.

image from author

This command will show all container IDs only.

image from the author

Docker Run

Using the naming command you can assign a container name you prefer, in the below put the name for the ubuntu container. This docker run command is a combination of docker pull and docker start command (docker run = docker pull + docker start).

image from author

Docker RM — Remove

This command use deletes Specific container. To remove all containers that existing, can use the docker rm $(docker ps -aq) command also. I have checked the existing containers before and after removing the container below.

Note:- when you typing container id, no need to type the whole id. You can type the first 3 or 4 letters and those letters should be unique within your existing containers.

docker rm
image from author

Docker Images

This will list all the information of downloaded images from the Docker hub.

image from author

This command will list image IDs only.

image from author

Docker RMI — Remove Image

This command will remove the specific Docker image.

image from author

Docker Stop

This will stop the container that runs.

image from author

Docker Kill

This will kill the whole process of the container that runs. There is a difference between the stop and kill commands.

  • docker stop - try to stop it politely. This will take some time to stop the container.
  • docker kill - this will stop the main entry point of the process and stop it immediately.
image from author

Docker Detached Mode

  • docker detached mode means that a Docker container runs in the background of your terminal.
  • It does not receive input or display output. Using detached mode also allows you to close the opened terminal session without stopping the container.
image from author

This command will run the container in detached mode and stop the container after 1000 seconds.

image from author

Docker Logs

This will show all the logs of the particular container.

image from author

Docker Stats

This is showing how much resources are consuming each time. Every second refresh those values and get updated information.

image from author

Docker Inspect

This will show more container properties like IP address, mac address of the container.

image from author

Wrap-Up

If you have some knowledge about Docker and are pretty much confident with the basic stuff and to expand your knowledge hopefully this overview has helped you better understand Docker.

Thanks for reading!

--

--