Script Valley
Docker: Complete Course
Docker FundamentalsLesson 1.4

Essential Docker CLI commands every developer must know

docker run flags, docker stop, docker rm, docker exec, docker logs, docker inspect, port mapping, detached mode

The Commands You Will Use Every Day

Docker CLI command lifecycle

Knowing ten commands covers 90% of day-to-day Docker work. Here they are with real examples.

Running Containers

# Run interactively, remove on exit
docker run -it --rm ubuntu bash

# Run in background (detached), map port 8080 on host to 80 in container
docker run -d -p 8080:80 --name my-nginx nginx

# Pass environment variables
docker run -d -e POSTGRES_PASSWORD=secret postgres:16

Managing Running Containers

# Execute a command inside a running container
docker exec -it my-nginx bash

# Stream logs
docker logs -f my-nginx

# Stop and remove
docker stop my-nginx
docker rm my-nginx

# Stop and remove in one shot
docker rm -f my-nginx

Cleanup

# Remove all stopped containers, unused images, networks, build cache
docker system prune -a

The -d flag detaches the container — it runs in the background and gives you your terminal back. The -p host:container flag binds a host port to the container port. Without -p, the container's port is unreachable from your browser.

Up next

How Docker volumes work and when to use them

Sign in to track progress