After this lesson, you will be able to: Use docker run, ps, logs, exec, stop, rm and rmi confidently. Understand the difference between an image and a container.
Image is the blueprint; container is the running instance. Master the daily-driver commands first; the rest of the sub-track builds on them.
The eight commands you'll type most often.
docker run hello-world # download + run imagedocker run -d nginx # detached (background)docker run -d -p 8080:80 nginx # publish host:8080 -> container:80docker run -it ubuntu bash # interactive (use for exploring images)docker run --rm -it alpine sh # --rm removes the container after it exitsdocker run -d --name web nginx # give it a name (instead of random)docker ps # running containersdocker ps -a # ALL containers (including stopped)docker logs web # show the container's stdout/stderrdocker logs -f web # followdocker exec -it web bash # shell into a running containerdocker stop web # graceful stop (SIGTERM, then SIGKILL after 10s)docker rm web # remove a stopped containerdocker rm -f web # stop + remove in onedocker rmi nginx # remove an image
Image = immutable bundle of filesystem layers + metadata (entrypoint, env, ports). Like a class. Container = running instance of an image. Like an object. You can spawn many containers from one image. Each gets its own writable layer on top of the image's read-only layers. `docker images` lists images; `docker ps` lists containers. Don't conflate the two.
These let you configure a container without rebuilding the image.
# Environment variablesdocker run -e DATABASE_URL='postgres://...' -e LOG_LEVEL=debug myappdocker run --env-file .env myapp# Port mapping (host:container)docker run -p 3000:3000 myappdocker run -p 127.0.0.1:3000:3000 myapp # bind only to localhost# Mount a host directory into the containerdocker run -v $PWD:/app -w /app node:20 npm test# -v bind mount (host_path:container_path)# -w set working directory inside container# Named volume (managed by Docker)docker volume create pgdatadocker run -v pgdata:/var/lib/postgresql/data postgres
`docker inspect <name>` dumps full JSON about a container (IP, mounts, env, networks). `docker stats` shows live CPU/RAM/IO per container, like `top` for containers. `docker top <name>` lists processes inside a container. `docker diff <name>` shows what changed in the container's filesystem vs the image.
Running containers without `--rm` in dev; you end up with hundreds of stopped containers polluting `docker ps -a`. Forgetting `-p`. The container is running but you can't reach its port from the host. `docker exec` to 'fix' a misconfigured container instead of rebuilding. Cattle, not pets. Filling the disk with old images. `docker system prune` is your friend (asks before deleting). Mounting host paths into containers that run as root. The container can chown/chmod your host files.
Pick the highest-leverage diagnostic.
Sign in and purchase access to unlock this lesson.