Basic Docker Commands

List Docker Containers

docker ps

Lists all running containers.

List All Docker Containers

docker ps -a

Lists all containers, including those that are stopped.

Start a Docker Container

docker start <container_name>

Starts a stopped container.

Stop a Docker Container

docker stop <container_name>

Stops a running container.

Remove a Docker Container

docker rm <container_name>

Removes a container. Use -f to force remove a running container.

Remove a Docker Image

docker rmi <image_name>

Removes an image from the local storage.

Build a Docker Image

docker build -t <image_name> .

Builds an image from the Dockerfile in the current directory.

Run a Docker Container

docker run -d --name <container_name> <image_name>

Runs a container from an image in detached mode.

List Docker Images

docker images

Lists all images stored locally.

View Docker Logs

docker logs <container_name>

Displays logs from a container.

Access a Running Container

docker exec -it <container_name> /bin/bash

Opens an interactive terminal session in a running container.

Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. Here are some basic commands:

Start Services

docker-compose up

Starts and runs all the services defined in a docker-compose.yml file.

Stop Services

docker-compose down

Stops and removes all containers, networks, and volumes defined in a docker-compose.yml file.