how about we do some...dockering together?
software development has drastically changed in recent years, not least due to the growing importance of containerization. one name stands out in particular: docker. in this blog post, you’ll learn what docker is, how it works, and why it has transformed the way applications are developed, tested, and deployed. we’ll also look at concrete use cases and provide practical tips for getting started
what is docker?
docker is an open-source platform for containerizing applications. it allows software to be packaged into so-called containers, including all dependencies (such as libraries, runtimes, and configurations). these containers run isolated from the host system but are lighter and faster than traditional virtual machines (VMs).containers are especially popular because they:
- are portable – they run on any system with the Docker engine.
- start quickly – compared to VMs, which need to boot an entire operating system.
- are easy to version and manage.
docker was released in 2013 and has since established itself as the standard in the world of containers. traditional software development often suffers from the so-called “It works on my machine” problem. an application works on the developer’s PC but not on the server. the reasons for this are usually differences in:
- operating systems
- dependencies
- environment variables
- network configurations
docker solves this problem quite elegantly, as everything an application needs is included within a container. the result is a consistent runtime environment, no matter where the application is running – whether on a developer’s PC, in the cloud, or on a test server.
docker vs. vm
| feature | docker-container | virtual machine |
|---|---|---|
| start time | seconds | minutes |
| resource consumption | small amount | high |
| isolation level | at process level | at OS level |
| portability | very high | restricted |
how does docker works?
The core component is the docker Engine – a client-server system with the following main components:
- docker CLI (command line interface): user input tool
- docker daemon: background service that manages containers
- docker images: snapshot of an application including its enviroment
- docker container: runtime instance of an image
a typical workflow look like this:
- the developer writes a dockerfile – a text file that describes how an image should be built
- an image is created from this using docker build
- the image can be started as a container using docker run
example of a simple dockerfile
Dockerfile
FROM python:3.10
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
imagine you want to run a small python web application using flask. without docker, you’d have to make sure that python and flask are installed on every system. with Docker, it’s much simpler. you can write a dockerfile (see above) and then build the image with docker build -t my-flask-app and start the container with docker run -d -p 5000:5000 my-flask-app and done! the application is running on http://localhost:5000. many applications consist of multiple components, such as a web server, a database, and a cache. with Docker Compose, you can define these containers in a single docker-compose.yml file and start them together.
example:
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
db:
image: postgres:13
environment:
POSTGRES_PASSWORD: s3cr3t
with docker-compose up everything is started at once.
security in docker
even though Docker isolates processes, this doesn’t automatically mean complete security. Some important security aspects:
- containers often run as root – a risk!
- containers should contain only the bare essentials (principle of the smallest attack surface)
- configure networks and volumes specifically and do not share everything
- perform regular updates of the images
hint: Use official images from the docker hub (https://hub.docker.com), pay attention to security updates and use tools like docker scan or trivy.
sources
- Docker-Documentation
- Docker Hub
- „Docker für Entwickler“ – Heise Developer, 2021
- „The Docker Book“ of James Turnbull, 2020
- OWASP Docker Security Cheat Sheet
- Post of DigitalOcean