chalvien.eu
GuidesDocker

Docker Commands for Daily Use

A brief, junior-friendly guide to the Docker commands you will use most often in local development.

Introduction

This quick guide covers the Docker commands you will run most days while developing apps.

1. Check Docker status and version

Use these first when something feels off.

docker --version
docker info

2. Work with images

Build, list, and remove images.

# Build an image from Dockerfile in current folder
docker build -t my-app:dev .

# List local images
docker images

# Remove an image
docker rmi my-app:dev

3. Run and manage containers

Start, inspect, stop, and remove containers.

# Run a container in background
docker run -d --name my-app -p 3000:3000 my-app:dev

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# Stop and remove a container
docker stop my-app
docker rm my-app

4. Read logs and open a shell

Very useful for debugging.

# View logs
docker logs my-app

# Follow logs live
docker logs -f my-app

# Open a shell inside container
docker exec -it my-app sh

5. Copy files in or out

Helpful for quick checks and backups.

# Copy file from host to container
docker cp ./local.txt my-app:/tmp/local.txt

# Copy file from container to host
docker cp my-app:/tmp/local.txt ./copied.txt

6. Clean up unused resources

Use carefully to free disk space.

# Remove stopped containers
docker container prune

# Remove dangling images
docker image prune

# Remove unused containers, networks, and images
docker system prune

7. Daily Docker Compose commands

If your project uses docker-compose.yml.

# Start services in background
docker compose up -d

# Rebuild and start services
docker compose up -d --build

# View service status
docker compose ps

# View logs
docker compose logs -f

# Stop and remove services
docker compose down

Common flow (quick routine)

docker compose up -d --build
docker compose ps
docker compose logs -f
# when done
docker compose down

Tips for juniors

  • Keep container names simple (--name api, --name db).
  • Use docker ps and docker logs -f <name> as your first debug steps.
  • Prefer docker compose for multi-service projects.
  • Run cleanup commands occasionally so Docker does not fill your disk.

Common errors and quick fixes

  1. Port already in use

Error usually looks like: bind: address already in use.

# See what is using port 3000
lsof -i :3000

# If it is a Docker container, stop it
docker ps
docker stop <container_name_or_id>

# Or run your app on another host port
docker run -d --name my-app -p 3001:3000 my-app:dev
  1. Container name already in use

Error usually looks like: Conflict. The container name is already in use.

# Find container with the same name
docker ps -a

# Remove old container, then run again
docker rm <container_name>

# Or pick a different name
docker run -d --name my-app-v2 -p 3000:3000 my-app:dev
  1. Cannot connect to Docker daemon

Error usually looks like: Cannot connect to the Docker daemon.

# Check Docker status
docker info

# On macOS, start Docker Desktop and wait until it says "Docker is running"
# Then retry your command
docker ps

If docker info still fails, restart Docker Desktop and try again.

On this page