Docker Commands

Essential Docker commands for containerization, images, and orchestration. Copy commands with one click.

Getting Started

Run Container

docker run -d -p 80:80 nginx

Run nginx in detached mode on port 80

Interactive Container

docker run -it ubuntu bash

Run Ubuntu container with interactive bash

List Containers

docker ps

List running containers

List All Containers

docker ps -a

List all containers (including stopped)

Container Management

Stop Container

docker stop <container_id>

Stop a running container

Remove Container

docker rm <container_id>

Remove a container

Execute Command

docker exec -it <container_id> bash

Execute bash in running container

View Logs

docker logs <container_id>

View container logs

Image Management

List Images

docker images

List all Docker images

Pull Image

docker pull nginx

Download image from registry

Build Image

docker build -t myapp .

Build image from Dockerfile

Remove Image

docker rmi <image_id>

Remove Docker image

Docker Compose

Start Services

docker-compose up

Start all services

Start in Background

docker-compose up -d

Start services in detached mode

Stop Services

docker-compose down

Stop and remove services

View Logs

docker-compose logs

View logs from all services