In the last post, we ran our very first container with docker run hello-world
.
But how do we see which containers are running? And how do we manage them?
Thatβs where docker ps
comes in.
π List containers with docker ps
Run:
docker ps
`
This shows all running containers.
Youβll see columns like:
- CONTAINER ID β unique ID for the container
- IMAGE β which image it came from
- STATUS β running time
- PORTS β which ports are exposed
- NAMES β an auto-generated (or custom) name
π Show all containers (including stopped)
By default, docker ps
only shows running containers.
To see all, use:
bash
docker ps -a
This will list containers that have already exited too.
π Stop a container
If you want to stop a running container:
bash
docker stop <container_id_or_name>
Example:
bash
docker stop funny_panda
β Remove a container
Stopped containers still take up space.
To remove them:
bash
docker rm <container_id_or_name>
Example:
bash
docker rm funny_panda
π§Ή Clean up all stopped containers
To remove all stopped containers at once:
bash
docker container prune
Docker will ask for confirmation before deleting.
π Summary
-
docker ps
β list running containers -
docker ps -a
β list all containers (running + stopped) -
docker stop
β stop a container -
docker rm
β remove a container -
docker container prune
β clean up everything stopped
π‘ Next: weβll explore Docker Images β how to list, pull, and remove them.
Follow me on Threads/Instagram for more Docker explained simply π³
`
Top comments (0)