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

CommandDescription
docker compose upBuild if needed, create, start, and attach to all services in the Compose project.
docker compose up -dStart all Compose services in the background.
docker compose up --buildRebuild service images first, then start the services.
docker compose downStop and remove the project’s containers and networks.
docker compose down -vStop and remove containers, networks, and volumes used by the project.
docker compose psShow the status of containers in the Compose project.
docker compose logsShow logs from all Compose services.
docker compose logs -fShow and follow live logs from all Compose services.
docker compose exec web shOpen a shell or run a command inside the running web service container.
docker compose configShow the final resolved Compose configuration.

1) Core Compose commands

CommandDescription
docker compose upBuild if needed, create, start, and attach to all services in the Compose project.
docker compose up -dStart all Compose services in the background.
docker compose up --buildRebuild service images first, then start the services.
docker compose downStop and remove the project’s containers and networks.
docker compose down -vStop and remove containers, networks, and volumes used by the project.
docker compose psShow the status of containers in the Compose project.
docker compose logsShow logs from all Compose services.
docker compose logs -fShow and follow live logs from all Compose services.
docker compose exec web shOpen a shell or run a command inside the running web service container.
docker compose configShow the final resolved Compose configuration.

2) Compose workflow commands

CommandDescription
docker compose buildBuild or rebuild the images for services in the Compose file.
docker compose pullDownload service images without starting containers.
docker compose pushPush service images to a registry.
docker compose createCreate service containers without starting them.
docker compose startStart existing Compose service containers.
docker compose stopStop running Compose services without removing them.
docker compose restartRestart running Compose services.
docker compose run --rm web shRun a one-off shell or task in a temporary container for the web service.
docker compose imagesList images used by the Compose project.
docker compose topShow running processes inside Compose containers.

3) Compose monitoring and file operations

CommandDescription
docker compose port web 8000Show which host port maps to port 8000 in the web service.
docker compose statsShow live CPU, memory, and resource usage for Compose containers.
docker compose eventsStream real-time events from Compose containers.
docker compose watchWatch files and rebuild or refresh containers when files change.
docker compose cp ./file.txt web:/tmp/file.txtCopy a file between your machine and a Compose container.
docker compose export web > webfs.tarExport a service container’s filesystem as a tar file.
docker compose lsList Compose projects currently known to Docker.
docker compose versionShow the installed Docker Compose version.
docker compose pausePause processes inside Compose service containers.
docker compose unpauseResume processes inside paused Compose service containers.

4) Core container commands

CommandDescription
docker run IMAGECreate and start a new container from an image.
docker run -d IMAGERun a new container in detached background mode.
docker run --name myapp IMAGERun a new container and assign it a fixed name.
docker run -p 8000:8000 IMAGERun a container and map host port 8000 to container port 8000.
docker psList running containers.
docker ps -aList all containers, including stopped ones.
docker logs CONTAINERShow logs for one container.
docker logs -f CONTAINERShow and follow live logs for one container.
docker exec -it CONTAINER shOpen an interactive shell or run a command inside a running container.
docker inspect CONTAINERShow detailed low-level JSON information about a container.

5) Container control and debugging

CommandDescription
docker stop CONTAINERGracefully stop a running container.
docker start CONTAINERStart a stopped container.
docker restart CONTAINERRestart a container.
docker kill CONTAINERForce-stop a running container immediately.
docker rm CONTAINERRemove 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 CONTAINERShow processes running inside a container.
docker statsShow live resource usage for containers.
docker port CONTAINERShow port mappings for a container.

6) Advanced container lifecycle commands

CommandDescription
docker container pause CONTAINERPause all processes inside a running container.
docker container unpause CONTAINERResume all processes inside a paused container.
docker container rename old_name new_nameRename an existing container.
docker container wait CONTAINERWait for a container to stop and print its exit code.
docker container pruneRemove all stopped containers.
docker container create IMAGECreate a container from an image without starting it.
docker container diff CONTAINERShow filesystem changes made inside a container.
docker container export CONTAINER > fs.tarExport a container filesystem as a tar archive.
docker container update --cpus 1 CONTAINERChange runtime settings like CPU or memory limits for a container.
docker container commit CONTAINER myimage:debugCreate a new image from a container’s current state.

7) Image and build commands

CommandDescription
docker build -t myapp .Build an image from the current folder’s Dockerfile and tag it as myapp.
docker imagesList local Docker images.
docker image inspect IMAGEShow detailed JSON information about an image.
docker pull IMAGEDownload an image from a registry.
docker push IMAGEUpload an image to a registry.
docker tag SOURCE_IMAGE TARGET_IMAGECreate another tag for the same image.
docker image history IMAGEShow the layer history of an image.
docker image save -o image.tar IMAGESave an image to a tar archive.
docker image load -i image.tarLoad an image from a tar archive.
docker rmi IMAGERemove one or more local images.

8) Cache, volume, and disk usage commands

CommandDescription
docker image pruneRemove unused dangling images.
docker builder pruneRemove unused build cache from the builder.
docker buildx pruneRemove unused Buildx build cache.
docker volume lsList Docker volumes.
docker volume create mydataCreate a named volume.
docker volume inspect mydataShow detailed information about a volume.
docker volume rm mydataRemove a volume that is not being used.
docker volume pruneRemove all unused volumes.
docker compose volumesList volumes associated with Compose services.
docker system dfShow Docker disk usage for images, containers, volumes, and cache.

9) Network and system commands

CommandDescription
docker network lsList Docker networks.
docker network create appnetCreate a new Docker network.
docker network inspect appnetShow detailed information about a network.
docker network connect appnet CONTAINERConnect a running container to a network.
docker network disconnect appnet CONTAINERDisconnect a running container from a network.
docker network rm appnetRemove a network.
docker network pruneRemove all unused networks.
docker versionShow Docker client and server version information.
docker infoShow system-wide Docker installation details.
docker system eventsStream real-time Docker daemon events.

10) Cleanup, registry, init, context, and manifest commands

CommandDescription
docker system pruneRemove unused containers, networks, dangling images, and build cache.
docker system prune --volumesRemove unused containers, networks, images, cache, and unused volumes.
docker loginSign in to a Docker registry such as Docker Hub.
docker logoutSign out from a Docker registry.
docker initGenerate starter Docker files for a project.
docker context lsList available Docker contexts.
docker context showShow the current Docker context name.
docker context inspect myctxShow detailed information about a specific Docker context.
docker context use myctxSwitch Docker to use a different context.
docker manifest inspect IMAGEShow the manifest details of an image, including platform information.