Docker is a platform that enables you to package applications and their dependencies into containers — lightweight, portable, and consistent environments for running software.
🧱 1. Images and Containers
Command
Purpose
docker build -t <name> .
Builds a Docker image from a Dockerfile in the current directory.
docker pull <image>
Downloads an image from Docker Hub or a registry.
docker images
Lists all images on the local system.
docker rmi <image>
Removes an image from the local system.
docker run <image>
Creates and starts a container from an image.
docker run -it <image> /bin/bash
Starts a container interactively with terminal access.
docker ps
Lists running containers.
docker ps -a
Lists all containers (running and stopped).
docker stop <container>
Gracefully stops a running container.
docker kill <container>
Forcefully stops a container.
docker rm <container>
Removes a stopped container.
docker exec -it <container> <command>
Runs a command inside a running container.
docker logs <container>
Shows logs from a container’s stdout/stderr.
🧰 2. Volumes and Persistent Storage
Command
Purpose
docker volume create <name>
Creates a named volume.
docker volume ls
Lists volumes.
docker volume rm <name>
Deletes a volume.
docker run -v <volume>:/path/in/container <image>
Mounts a volume inside a container.
🌐 3. Networks and Communication
Command
Purpose
docker network ls
Lists available Docker networks.
docker network create <name>
Creates a custom network.
docker run –network=<network> <image>
Attaches a container to a specified network.
🧾 4. Docker Compose (Multi-Container Apps)
Command
Purpose
docker-compose up
Builds (if needed) and starts services defined in docker-compose.yml.
docker-compose up -d
Same as above, but runs in detached mode.
docker-compose down
Stops and removes all resources created by up.
docker-compose build
Builds the images defined in the compose file.
docker-compose ps
Lists containers managed by Compose.
docker-compose exec <service> <cmd>
Runs a command in a running service container.
🧼 5. Clean-up and Maintenance
Command
Purpose
docker system df
Shows disk usage of images, containers, volumes.
docker system prune
Removes all unused data (containers, images, networks, volumes).
docker image prune
Removes unused images.
docker container prune
Removes stopped containers.
🧪 6. Miscellaneous
Command
Purpose
docker info
Shows general Docker system information.
docker version
Shows Docker version (client and server).
`docker inspect <container
image>`
docker tag <src> <repository:tag>
Tags an image with a new name and optionally a version.
docker push <repository:tag>
Pushes an image to a remote registry.
🧭 Example Workflow
# Build an image from a Dockerfile
docker build -t myapp .
# Run a container from the image
docker run -d -p 8080:80 --name myapp-container myapp
# View logs
docker logs myapp-container
# Execute a shell inside the container
docker exec -it myapp-container /bin/bash
# Stop and remove the container
docker stop myapp-container
docker rm myapp-container