Published on: 23 June 2025

I had to explain to a friend how docker works, why use it and for what for
Docker is confusing at first. If you havent look into contaneiration or you are starting it can be complicated to grasp what it does and why is needed for.
This is the foundation most modern DevOps stacks are built on. Think of containers like portable blocks that you can run everywhere.
They are a package that contain:
- Your app
- Dependencies
- Configuration
With this info (a blueprint of what your app needs), your docker image is created and docker create containers from it and run them.
FROM python:3.12
WORKDIR /usr/local/app
# Install the application dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy the source code
COPY src ./src
EXPOSE 5000
# Setup an app user so the container doesn't run as the root user
RUN useradd app
USER app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0"]
This is an example of a Dockerfile.
With this file and runing docker build -t MyappImage
it will create a docker image with those intructions:
- Grab python:3.12 as base operating system, it’s a linux distro with python 3.12 preinstalled
- copy the requirements.txt file
- install requirements
- copy the code
- expose the 5000 port to access the container
- use a non root user
- execute
uvicorn app.main:app --host 0.0.0.0
And that’s it. this image MyAPPImage
can be used in your own computer to run the app, or you can publish it to any docker registry (where images are stored and accessible) and then from any docker engine you can docker run MyAppImage
and execute your app, anywhere (with a docker engine…).
This is the how, but the Why use it? Because it gives you:
- Portability across environments: if doesn’t matter if you need windows or linux, there are base images to work with.
- Scalability with ease: you can scale your app horizontally or vertically (with docker commands)
- Isolation between services: each container is isolated from all others containers.
- Reproducibility in deployments: if you can deploy it in a docker engine, you can deployit on all docker engines
- Under the hood, Docker uses:
- Namespaces for isolation and security
- groups to manage resources
- file systems to build efficient layers
- Built-in networking for container communication
- Docker Compose to run multi-container apps
Understanding Docker is the first step toward mastering Kubernetes, CI/CD, and cloud-native architecture, but those are another talk with other beer.