docker ps
Lists all running containers.
docker ps -a
Lists all containers, including those that are stopped.
docker start <container_name>
Starts a stopped container.
docker stop <container_name>
Stops a running container.
docker rm <container_name>
Removes a container. Use -f
to force remove a running container.
docker rmi <image_name>
Removes an image from the local storage.
docker build -t <image_name> .
Builds an image from the Dockerfile in the current directory.
docker run -d --name <container_name> <image_name>
Runs a container from an image in detached mode.
docker images
Lists all images stored locally.
docker logs <container_name>
Displays logs from a container.
docker exec -it <container_name> /bin/bash
Opens an interactive terminal session in a running container.
Docker Compose is a tool for defining and running multi-container Docker applications. Here are some basic commands:
docker-compose up
Starts and runs all the services defined in a docker-compose.yml
file.
docker-compose down
Stops and removes all containers, networks, and volumes defined in a docker-compose.yml
file.