Introduction to Docker
A practical primer on containers, images, and Compose for running repeatable services on Linux.
What Docker is.
Docker runs applications in containers: isolated processes with their own filesystem view, dependencies, and configuration. Unlike a traditional virtual machine, a Linux container shares the host kernel. This often makes container deployment lighter than operating a separate guest OS for every service.
Images, containers, volumes.
- Image: the packaged filesystem and metadata from which containers are created.
- Container: a running or stopped instance of an image.
- Volume: persistent data stored outside a disposable container filesystem.
- Network: a way for containers to discover and communicate with permitted peers.
Launch a web server.
With Docker installed, this command runs an Nginx container and publishes its web port locally:
docker run --rm -d --name example-web -p 127.0.0.1:8080:80 nginx:stableVisit http://127.0.0.1:8080 from the host. When you are finished, remove the container with docker stop example-web. Binding to 127.0.0.1 avoids exposing the example on every network interface.
Turn a command into configuration.
For repeatable deployments, put the service definition in compose.yaml:
services:
web:
image: nginx:stable
ports:
- "127.0.0.1:8080:80"
restart: unless-stoppedRun docker compose up -d to start it and docker compose down to stop and remove the service container. A restart policy helps after crashes or daemon restarts; it does not replace monitoring or backups.
Design for maintenance.
- Pin known-good image versions rather than relying blindly on floating tags.
- Use named volumes or clearly managed directories for persistent data.
- Keep secrets out of repositories and public Compose examples.
- Publish only ports you need and restrict privileges.
- Back up both application data and the configuration required to restore it.
- Review upstream documentation before copying installation commands, which change over time.