Commands On Docker -Basic Guide

Prashant
2 min readDec 7, 2023

--

Are you ready to dive into the world of containers and discover how Docker commands can transform the way you work? Let’s get started.

Let’s check for the installed docker version

docker --version

If docker is not found on your system, download it from here.

Commands and Description.

docker info

sudo docker info

To see more information on the Docker running on the system.

docker pull

To pull the images.

docker run <Image>

This command is used to run a command in a docker container

docker images

To see the list of docker images on the system

docker rmi : ImageID

To remove the docker image

docker images -q

Only returns the image ID’s of the images on the docker host

docker inspect Repository

This command is used to see the details of a repository (images, container)

docker ps -a

To list all containers on the machine

docker ps

Shows all running containers.

docker history ImageId

To see all the commands that were run with an image via a container

docker top containerId

To see the top processes within a container

#Stop 

docker stop containerId

#delete

docker rm containerId

#statistics

docker stats containerId

#attach to running container
docker attach containerId

#pause
docker pause containerId

#unpause and kill

docker unpause containerId

docker kill containerId

Basic operation command with container

service docker stop

This command is used to stop the Docker daemon process

service docker start

To start the docker daemon process

docker build -t imageName:TagName <directory>

To build docker file.

docker run --rm -it <image>

Remove the image by docker rmi.

docker run  -d -p --name <Name> <Images>

Close the terminal and keeps the container running, this is Detached mode.

  • -d will detach terminal
  • -p will publish all expose port to random ports
  • — name corresponds to a name we want to give
docker port [containerId]

To see the running port.

docker network ls

To list networks.

docker exec [options] CONTAINER COMMAND [ARG ..]

To run a new command in running container.

docker image prune

Remove all unused images

#login into docker
docker login -u <username>

#publish an image to dockerHub
docker push <username>/<image_name>

#search Hub for image
docker search <image_name>

#pull an image from a docker Hub
docker pull <image_name>

Docker hub commands.

#fetch and follow the logs of a container
docker logs -f <container_name>

nsenter

This method allows one to attach to a container without existing the container.

Disclaimer

I am currently in the process of learning and exploring new concepts, including the topics discussed in this content. While I strive to provide accurate and helpful information, please be aware that I might not be an expert in these subjects. Any explanations or guidance offered are based on my current understanding and learning journey.

--

--