Docker is a containerization platform that packages an app and its dependencies into a portable unit called an image. Run that image anywhere as a container and it behaves the same across environments.
Containers share the host OS kernel and isolate processes; VMs virtualize hardware and include a full guest OS per VM. Containers are typically smaller and start faster.
docker build -t myapp .
docker run --rm -p 8080:8080 myapp
docker ps
docker logs <container>
docker exec -it <container> sh
docker system prune -f
docker image prune -f
docker volume prune -f
Use Docker Compose to run an app stack (web + db + cache, etc.) from a single YAML file.
services:
web:
build: .
ports:
- "8080:8080"
db:
image: mariadb:11
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
docker compose up -d
docker compose logs -f
docker compose down