Docker Commands

Pardhu Guttikonda
3 min readOct 14, 2021

Commonly used docker commands to handle images, containers, and volumes

🙌🏻 Introduction:

Docker is an open-source containerization platform(Paas Product) which enables developers to package applications into containers so that we can run them anywhere.

Photo by Guillaume Bolduc on Unsplash

⛹️‍♂️ Terminologies in Docker:

1. Docker Image

  • It is a file comprised of multiple layers, used to execute code in a Docker container.
  • Comprises a set of instructions used to create docker containers.

2. Docker Container

  • It is a runtime instance of an image.
  • Allows developers to package applications with all parts needed such as libraries and other dependencies.

3. Docker file

  • It is a text document that contains necessary commands which on execution help assemble a Docker Image.
  • Docker image is created using a Docker file.

4. Docker Engine

  • The software that hosts the containers is called the Docker Engine.
  • The docker Engine is a client-server based application
  • The docker engine has 3 main components:
  • Server: It is responsible for creating and managing Docker images, containers, networks, and volumes on the Docker. It is referred to as a daemon process.
  • REST API: It specifies how the applications can interact with the Server and instructs it what to do.
  • Client: The Client is a docker command-line interface (CLI), that allows us to interact with Docker using the docker commands.

5. Docker Hub

  • Docker Hub is the official online repository where you can find other Docker Images that are available for use.
  • It makes it easy to find, manage, and share container images with others.
Photo by Markus Spiske on Unsplash

📡 Commonly used Commands:

  • Get currently installed version of docker
docker -version
docker pull <image_name>
  • Creates containers from an image
docker run -it -d <image_name>
  • list all running containners
docker ps
  • List all running and exited containers
docker ps -a
  • displays the logs of running container.
docker logs -f <container_id>
  • List all volumes
docker volume ls
  • Access the running container
docker exec -it <container_id> bash
  • Stop a running Container
docker stop <container_id>
  • kills the container by stopping its execution immediately. difference between ‘docker kill’ and ‘docker stop’ is that ‘docker stop’ gives the container time to shutdown gracefully, in situations when it is taking too much time for getting the container to stop, one can opt to kill it
docker kill <container_id>
  • Create a new image of an edited container on the local system.
docker commit <conatainer id> <username/imagename>
  • Login to docker hub repository
docker login
  • Push an image to the docker hub repository
docker push <username/image name>
  • List all locally stored docker images
docker images
  • Removes all images
docker rmi $(docker images -a -q)
  • Delete a stopped container
docker rm <container_id>
  • Delete an from local storage
docker rmi <image_id>
  • Build an image from specified docker file
docker build <path to docker file>
  • this clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container)
docker system prune
  • Removes any stopped containers and all unused images
docker system prune -a
  • Stop all containers
docker stop $(docker ps -a -q)
  • Remove all containers
docker rm $(docker ps -a -q)
  • Remove all dangling volumes.
docker volume prune
  • Remove a container its respective volumes
docker rm -v <container_name>   (remove a container its volume)
  • docker_compose.yml is a file containing the instructions to run set of image in one go.
docker-compose up

Conclusion:-

  • First we will build an image using a dockerFile. Now the image will there in our local storage. Now to publish that image we need to login with the docker hub and push to DockerHub.
  • Now we pull that image to any of the system.Using docker pull command

Ref:- https://www.geeksforgeeks.org/introduction-to-docker/

--

--