Docker
devopsdockerGuideBeginner
Docker Container Lifecycle & Management
Managing Docker containers, environment variables, port forwarding, bind mounts, and volume persistence.
Verified: 2026-09-30
Tested on:docker 27.x, ubuntu 24.04
Platforms:
linuxmacoswindows
#docker#containers#devops#linux
Overview
A Docker container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Core Container Commands
# 1. Run container in background with port forwarding
docker run -d --name my-app -p 3000:3000 node:22-alpine
# 2. View running containers
docker ps
# 3. Stream real-time container logs
docker logs -f my-app
# 4. Open interactive shell inside running container
docker exec -it my-app sh
# 5. Stop and remove container
docker stop my-app && docker rm my-appVolume Persistence vs Bind Mounts
| Type | Syntax | Best Use Case |
|---|---|---|
| Named Volume | -v pgdata:/var/lib/postgresql/data | Database storage managed safely by Docker daemon. |
| Bind Mount | -v $(pwd):/app | Local development live code reload. |
| tmpfs Mount | --tmpfs /tmp | Sensitive ephemeral in-memory storage. |
Docker Images & Layer Architecture
Master Docker images, read-only layer caching, OverlayFS union filesystem, semantic image tagging, and image management.
Dockerfile Reference & Instructions
Complete reference for writing clean, efficient, and secure Dockerfiles using standard instructions like FROM, WORKDIR, COPY, RUN, CMD, and ENTRYPOINT.