Top Docker Commands for Beginners

Hi everyone,
i have come across some important docker commands and noted it , when i started to learn docker. i think these are most commonly used. i want to share these notes with you and hope it will be useful for beginners.

images : List docker images (without hidden intermediate images )

$ docker images

List all images

docker images -a

List images by name and tag

docker images <IMAGE_NAME:TAG>

rmi : docker remove image(rmi) by image id

docker rmi <IMAGE_ID>

To remove all docker image, use the below command(not recommended)

docker rmi $(docker images -a -q) -f

-q : quiet(Only show numeric IDs)
-f : force remove

run : run command will create a new container using the given image.

$ docker run <IMAGE_ID|IMAGE_NAME>

some run flags

$ docker run — rm -it <IMAGE_NAME> /bin/sh

— rm Automatically remove the container when it exits
-i : interactive
-t : terminal

To find out more about run, use docker run — help.

ps : List running containers

$ docker ps

List all containers

docker ps -a

-a:all(default shows just running)

rm : docker remove (rm) by container id

docker rm <CONTAINER_ID>

To remove all docker container, use the below command(not recommended)

docker rm $(docker ps -a -q) -f

-q : quiet(Only show numeric IDs)
-f : force remove

inspect : Inspect command is used to see basic information about container or image.

$ docker inspect <CONTAINER_ID>

start : start command is used to start container which is exist but stopped.

docker start -a <CONTAINER_ID>

-a: attach to terminal

logs : logs command is used to see container’s logs.

docker logs <CONTAINER_ID>

exec : SSH connection into a Docker container using this command by container Id or by name

docker exec -it <CONTAINER_ID|CONTAINER_NAME> /bin/bash

top : Display the running processes of a container(runs top command on the given container)

docker top <CONTAINER_ID>

network : docker network command used to manage docker networks

usege :

$ docker network create [OPTIONS] <NETWORK_NAME>

To create new docker network

$ docker network create -d bridge — subnet <NETWORK_NAME>

-d: driver (Driver to manage the network)

To remove docker network

$ docker network rm <NETWORK_NAME>

List all docker networks

$ docker network ls