Docker Containers

Container lifecycle management

Run Container

docker run image # run container from image
docker run -d image # run in detached mode
docker run -it image # run with interactive terminal
docker run --name mycontainer image # name the container
docker run --rm image # remove container after exit

List Containers

docker ps # list running containers
docker ps -a # list all containers
docker ps -q # show only container IDs
docker container ls # list running containers (alt)

Start/Stop Containers

docker start container # start stopped container
docker stop container # stop running container
docker restart container # restart container
docker pause container # pause container
docker unpause container # unpause container

Remove Containers

docker rm container # remove stopped container
docker rm -f container # force remove running container
docker container prune # remove all stopped containers

Kill Containers

docker kill container # kill running container
docker kill $(docker ps -q) # kill all running containers

Rename Container

docker rename old-name new-name # rename container