Docker Basics
Containers in practice — the commands that matter.
Core concepts
- Image: blueprint (read-only)
- Container: running instance of an image
- Volume: persistent data storage
- Compose: multi-container orchestration
Images
docker pull nginx:latest # pull from Docker Hub
docker images # list local images
docker rmi <image> # remove image
docker build -t myapp:1.0 . # build from DockerfileContainers
docker run -d -p 8080:80 nginx # run in background
docker run -it ubuntu bash # interactive shell
docker ps # running containers
docker ps -a # all containers
docker stop <id>
docker rm <id>
docker logs <id>
docker exec -it <id> bash # shell into running containerVolumes
docker volume create mydata
docker run -v mydata:/app/data myapp
docker run -v $(pwd):/workspace myapp # bind mountCompose
# docker-compose.yml
services:
web:
image: nginx
ports: ["8080:80"]
db:
image: postgres
environment:
POSTGRES_PASSWORD: secretdocker compose up -d
docker compose down
