Docker Command


Docker Images

docker images        # Lists all locally available images
docker rmi           # deletes unused images to free disk space.
docker rmi <id>      # Remove a specific image
docker rmi -f <id>   # Force remove a specific image

Docker Containers

docker ps            # Show running containers
docker ps -a         # Show all containers (running + stopped)

Managing Container

docker start <CONTAINER_NAME>       # Start an existing container
docker stop <CONTAINER_NAME>        # Stop a running container
docker restart <CONTAINER_NAME>     # Restart a running container
docker rm <CONTAINER_NAME>          # Remove a stopped container
docker rm -f <CONTAINER_NAME>       # Forcefully remove a container (stops it if running)

Pulling and Running an Image

docker pull ubuntu:24.04         # Downloads  image (if not already present)

docker run -it ubuntu:24.04 bash # Running Containers with bash Shells
docker run -it ubuntu:24.04 sh   # Running Containers with lightweight Shells

Naming Containers

docker run --name my_ubuntu -it ubuntu:24.04 bash

Why name containers?

  • Easier to manage containers
  • Avoids remembering container IDs