Why it matters
"It works on my machine" is one of the oldest problems in software. A container solves it by packaging an app with everything it needs: the runtime, libraries and settings. The same container runs on a developer's laptop, in the pipeline and on a cloud server. Docker appears in most Ghanaian DevOps adverts we read, and containers are the input to Kubernetes later in this track.
Images and containers
- An image is a read only package: a recipe already cooked and frozen.
- A container is a running copy of an image. You can run many containers from one image.
- A registry stores images so others can download them. Docker Hub and the cloud providers' registries are examples.
Containers are lighter than virtual machines because they share the host's Linux kernel instead of each running a full operating system.
A first Dockerfile
This packages a static site with the nginx web server:
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80FROM picks a base image, COPY adds your file and EXPOSE documents the port the app listens on.