Managing Containers

Listing and Inspecting

Example

docker ps lists running containers; -a includes stopped ones:

docker ps

Example output

CONTAINER ID   IMAGE        COMMAND                  STATUS         PORTS                  NAMES
3f1c9a7e5b2d   nginx:1.27   "/docker-entrypoint.…"   Up 2 minutes   0.0.0.0:8080->80/tcp   web

Everyday Commands

CommandDoes
docker logs -f webshow (and follow) the container's output
docker exec -it web shopen a shell inside a running container
docker stop web / docker start webstop / start again
docker restart webrestart
docker rm webdelete a stopped container (-f to force)
docker inspect webfull JSON details: IP, mounts, env, config
docker statslive CPU and memory usage
docker container prunedelete all stopped containers

Debugging a Container

Example

Read the logs and look inside:

docker logs --tail 3 web
docker exec -it web sh -c "ls /usr/share/nginx/html"

Example output

172.17.0.1 - - [07/Oct/2026:10:12:01 +0000] "GET / HTTP/1.1" 200 615
172.17.0.1 - - [07/Oct/2026:10:12:01 +0000] "GET /favicon.ico HTTP/1.1" 404 153
50x.html
index.html