Docker for Beginners
docker version
docker info
docker compose up
docker compose up –build
docker compose up -d
docker compose down
docker compose down -v
docker compose ps
docker compose logs
docker compose logs -f
docker compose build
docker compose restart
docker compose exec web sh
docker ps
docker ps -a
docker logs CONTAINER
docker logs -f CONTAINER
docker exec -it CONTAINER sh
docker images
docker system prune
1) Core Compose commands
| Command | Description |
|---|---|
docker compose up | Build if needed, create, start, and attach to all services in the Compose project. |
docker compose up -d | Start all Compose services in the background. |
docker compose up --build | Rebuild service images first, then start the services. |
docker compose down | Stop and remove the project’s containers and networks. |
docker compose down -v | Stop and remove containers, networks, and volumes used by the project. |
docker compose ps | Show the status of containers in the Compose project. |
docker compose logs | Show logs from all Compose services. |
docker compose logs -f | Show and follow live logs from all Compose services. |
docker compose exec web sh | Open a shell or run a command inside the running web service container. |
docker compose config | Show the final resolved Compose configuration. |
1) Core Compose commands
| Command | Description |
|---|---|
docker compose up | Build if needed, create, start, and attach to all services in the Compose project. |
docker compose up -d | Start all Compose services in the background. |
docker compose up --build | Rebuild service images first, then start the services. |
docker compose down | Stop and remove the project’s containers and networks. |
docker compose down -v | Stop and remove containers, networks, and volumes used by the project. |
docker compose ps | Show the status of containers in the Compose project. |
docker compose logs | Show logs from all Compose services. |
docker compose logs -f | Show and follow live logs from all Compose services. |
docker compose exec web sh | Open a shell or run a command inside the running web service container. |
docker compose config | Show the final resolved Compose configuration. |
2) Compose workflow commands
| Command | Description |
|---|---|
docker compose build | Build or rebuild the images for services in the Compose file. |
docker compose pull | Download service images without starting containers. |
docker compose push | Push service images to a registry. |
docker compose create | Create service containers without starting them. |
docker compose start | Start existing Compose service containers. |
docker compose stop | Stop running Compose services without removing them. |
docker compose restart | Restart running Compose services. |
docker compose run --rm web sh | Run a one-off shell or task in a temporary container for the web service. |
docker compose images | List images used by the Compose project. |
docker compose top | Show running processes inside Compose containers. |
3) Compose monitoring and file operations
| Command | Description |
|---|---|
docker compose port web 8000 | Show which host port maps to port 8000 in the web service. |
docker compose stats | Show live CPU, memory, and resource usage for Compose containers. |
docker compose events | Stream real-time events from Compose containers. |
docker compose watch | Watch files and rebuild or refresh containers when files change. |
docker compose cp ./file.txt web:/tmp/file.txt | Copy a file between your machine and a Compose container. |
docker compose export web > webfs.tar | Export a service container’s filesystem as a tar file. |
docker compose ls | List Compose projects currently known to Docker. |
docker compose version | Show the installed Docker Compose version. |
docker compose pause | Pause processes inside Compose service containers. |
docker compose unpause | Resume processes inside paused Compose service containers. |
4) Core container commands
| Command | Description |
|---|---|
docker run IMAGE | Create and start a new container from an image. |
docker run -d IMAGE | Run a new container in detached background mode. |
docker run --name myapp IMAGE | Run a new container and assign it a fixed name. |
docker run -p 8000:8000 IMAGE | Run a container and map host port 8000 to container port 8000. |
docker ps | List running containers. |
docker ps -a | List all containers, including stopped ones. |
docker logs CONTAINER | Show logs for one container. |
docker logs -f CONTAINER | Show and follow live logs for one container. |
docker exec -it CONTAINER sh | Open an interactive shell or run a command inside a running container. |
docker inspect CONTAINER | Show detailed low-level JSON information about a container. |
5) Container control and debugging
| Command | Description |
|---|---|
docker stop CONTAINER | Gracefully stop a running container. |
docker start CONTAINER | Start a stopped container. |
docker restart CONTAINER | Restart a container. |
docker kill CONTAINER | Force-stop a running container immediately. |
docker rm CONTAINER | Remove one or more containers. |
docker cp ./file.txt CONTAINER:/path/ | Copy a local file into a container. |
docker cp CONTAINER:/path/file.txt . | Copy a file from a container to your machine. |
docker top CONTAINER | Show processes running inside a container. |
docker stats | Show live resource usage for containers. |
docker port CONTAINER | Show port mappings for a container. |
6) Advanced container lifecycle commands
| Command | Description |
|---|---|
docker container pause CONTAINER | Pause all processes inside a running container. |
docker container unpause CONTAINER | Resume all processes inside a paused container. |
docker container rename old_name new_name | Rename an existing container. |
docker container wait CONTAINER | Wait for a container to stop and print its exit code. |
docker container prune | Remove all stopped containers. |
docker container create IMAGE | Create a container from an image without starting it. |
docker container diff CONTAINER | Show filesystem changes made inside a container. |
docker container export CONTAINER > fs.tar | Export a container filesystem as a tar archive. |
docker container update --cpus 1 CONTAINER | Change runtime settings like CPU or memory limits for a container. |
docker container commit CONTAINER myimage:debug | Create a new image from a container’s current state. |
7) Image and build commands
| Command | Description |
|---|---|
docker build -t myapp . | Build an image from the current folder’s Dockerfile and tag it as myapp. |
docker images | List local Docker images. |
docker image inspect IMAGE | Show detailed JSON information about an image. |
docker pull IMAGE | Download an image from a registry. |
docker push IMAGE | Upload an image to a registry. |
docker tag SOURCE_IMAGE TARGET_IMAGE | Create another tag for the same image. |
docker image history IMAGE | Show the layer history of an image. |
docker image save -o image.tar IMAGE | Save an image to a tar archive. |
docker image load -i image.tar | Load an image from a tar archive. |
docker rmi IMAGE | Remove one or more local images. |
8) Cache, volume, and disk usage commands
| Command | Description |
|---|---|
docker image prune | Remove unused dangling images. |
docker builder prune | Remove unused build cache from the builder. |
docker buildx prune | Remove unused Buildx build cache. |
docker volume ls | List Docker volumes. |
docker volume create mydata | Create a named volume. |
docker volume inspect mydata | Show detailed information about a volume. |
docker volume rm mydata | Remove a volume that is not being used. |
docker volume prune | Remove all unused volumes. |
docker compose volumes | List volumes associated with Compose services. |
docker system df | Show Docker disk usage for images, containers, volumes, and cache. |
9) Network and system commands
| Command | Description |
|---|---|
docker network ls | List Docker networks. |
docker network create appnet | Create a new Docker network. |
docker network inspect appnet | Show detailed information about a network. |
docker network connect appnet CONTAINER | Connect a running container to a network. |
docker network disconnect appnet CONTAINER | Disconnect a running container from a network. |
docker network rm appnet | Remove a network. |
docker network prune | Remove all unused networks. |
docker version | Show Docker client and server version information. |
docker info | Show system-wide Docker installation details. |
docker system events | Stream real-time Docker daemon events. |
10) Cleanup, registry, init, context, and manifest commands
| Command | Description |
|---|---|
docker system prune | Remove unused containers, networks, dangling images, and build cache. |
docker system prune --volumes | Remove unused containers, networks, images, cache, and unused volumes. |
docker login | Sign in to a Docker registry such as Docker Hub. |
docker logout | Sign out from a Docker registry. |
docker init | Generate starter Docker files for a project. |
docker context ls | List available Docker contexts. |
docker context show | Show the current Docker context name. |
docker context inspect myctx | Show detailed information about a specific Docker context. |
docker context use myctx | Switch Docker to use a different context. |
docker manifest inspect IMAGE | Show the manifest details of an image, including platform information. |
