Docker 29 cheatsheet

Docker 29: Containers

13 common Docker 29 tasks.

Run a container in the background

Start a named container and publish host port 8080 to container port 80.

docker run -d --name web -p 8080:80 nginx

Run a throwaway shell with your code mounted

Start a temporary container, mount the current folder and delete the container when you exit.

docker run --rm -it -v "$(pwd)":/app -w /app node:24 bash

List running containers

Show the containers that are currently running.

docker ps

List all containers

Include stopped containers.

docker ps -a

Stop a container

Ask a container to stop gracefully.

docker stop web

Start a stopped container

Start a container that already exists.

docker start web

Restart a container

Stop and start a container.

docker restart web

Remove a container

Delete a stopped container. Add -f to remove a running one.

docker rm web

Caution: Data stored in the container's own filesystem is lost. Data in named volumes is kept.

Open a shell in a running container

Run an interactive shell inside a container. Use bash if the image has it.

docker exec -it web sh

Follow container logs

Stream the last 100 lines and new output.

docker logs -f --tail 100 web

Inspect a container

Show its full configuration and state as JSON.

docker inspect web

Watch resource usage

Live CPU, memory and network use of running containers.

docker stats

Copy a file out of a container

Copy a file from a container to the current folder.

docker cp web:/etc/nginx/nginx.conf ./nginx.conf

Was this page helpful?