Essential Docker Commands: Streamlining Container Management

Shreyakajbaje
2 min readMar 24, 2024

--

Docker is an open container management platform that makes developing, shipping, and running applications easier based on containers — small and lightweight execution environments that make shared use of the operating system kernel and run them in isolation from one another. This transformative platform empowers developers to decouple applications from infrastructure, enabling rapid software delivery.

While working with this tool whether you’re a novice exploring the world of Docker or a seasoned pro seeking a quick reference having essential commands conveniently consolidated is a key. So here putting essential commands at your fingertips for streamlined container management.

Docker Container

  1. Run a Container from an Image -

docker run --name container_name image_name
#run the container in interactive shell mode
docker container run -it image_name /bin/bash

2. List all running and stopped Containers -

#list only running containers
docker ps
#list all running and stopped containers
docker ps -a

3. Start and Stop a running Container -

docker start container_name_or_id
docker stop container_name_or_id

4. Remove a running and stopped Container -

docker rm container_name_or_id
docker rm -f container_name_or_id #removing forcefully

5. Inspect details of a Container -

docker inspect container_name_or_id

6. View Container logs -

docker logs container_name_or_id

7. Pause and Unpause a Container -

docker pause container_name_or_id
docker unpause -f container_name_or_id

8. Restart and Rename a Container -

docker container retstart container_name_or_id
docker rename old_container new_container

Docker Images

  1. Build an Image from Dockerfile -

docker build -t image_name path_to_dockerfile

2. List all Local Images -

docker images
docker images ls

3. Push and Pull an image from Docker Hub -

docker push image_name:tag
docker pull image_name:tag

4. Remove a Local Image -

docker rmi image_name:tag
docker rm [image_name/image_id]

5. Tag an Image -

docker tag source_image:tag new_image:tag

6. Inspect details of an Image -

docker image inspect image_name:tag

7. Save and Load an Image to a tar Archive -

docker save -o image_name.tar image_name:tag
# -o used to write to a file instead of STDOUT
docker load -i image_name.tar
# -i to read from a file instead of input stream

8. Prune unused Image -

docker image prune
docker image prune --all #prune all unused images
docker image prune --force #donot prompt for confirmation

I hope all these necessary commands and concepts will help you get started with Docker real quickly. Thanks for giving it a read!

Happy Dockering !

--

--