Skills / DevOps and CI/CD / Containers with Docker
Containers with Docker
"It works on my machine" is one of the oldest problems in software. An app depends on a particular language version, libraries and settings, and a server that differs slightly can break it. Containers solve this by packaging the app together with everything it needs.
Docker is the most widely used container tool.
Key ideas:
- An image is a packaged, read-only template: your app, its runtime (such as Python or Node), its libraries and its settings
- A container is a running instance of an image. You can run many containers from one image
- A Dockerfile is the recipe that builds an image, step by step
A simple Dockerfile for a Python web app reads like a list of instructions:
FROM python:3.12-slimstarts from an official Python imageWORKDIR /appsets the working folderCOPY requirements.txt .thenRUN pip install -r requirements.txtinstalls the librariesCOPY . .adds your codeCMD ["python", "app.py"]says what to run when the container starts
Then docker build -t myapp . builds the image and docker run -p 8000:8000 myapp runs it, connecting port 8000 on your machine to port 8000 in the container.
Why teams love containers:
- The same image runs on a laptop, a test server and production
- Containers start in seconds and use fewer resources than full virtual machines, because they share the host's operating system kernel
- Each service can be packaged and updated on its own
Docker Compose runs several containers together, such as an app plus its database, from one file.
Security note: use official, minimal base images, keep them updated, and never bake passwords or keys into an image.
The tutor gives hints, not finished answers. Log in to use it.