Quick Intro To Docker

docker process symplified
Simple docker workflow

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:

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:

  1. Grab python:3.12 as base operating system, it’s a linux distro with python 3.12 preinstalled
  2. copy the requirements.txt file
  3. install requirements
  4. copy the code
  5. expose the 5000 port to access the container
  6. use a non root user
  7. 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:

Understanding Docker is the first step toward mastering Kubernetes, CI/CD, and cloud-native architecture, but those are another talk with other beer.