Docker is everywhere: in backend, in deployments, in data science, in AI… but the first time you hear about it usually sounds like black magic. Don’t worry: I’ll explain it clearly, with examples and a narrative thread that hooks.
What is Docker and why are everyone talking about it?
Imagine that you can package your application along with everything it needs to work —dependencies, libraries, environment— and take it to any machine without worrying about “it works on my PC but not in production”.
This is Docker.
A system that creates containers, small self-sufficient worlds where your app lives without bothering anyone and without being bothered by anything to her.
Key Concepts (without technical jargon)
A recipe. Contains the base operating system (lightweight), dependencies and your app.
A living instance of an image. How to run a pre-installed program.
The file where you say:
“I want this base, install it, copy my code and pull it like that”.
The “GitHub” of images Docker. Downloads and uploads images.
1. Installing Docker
On Linux (Ubuntu)
sudo apt update sudo apt install docker.io sudo systemctl enable docker sudo systemctl start docker
On Windows / Mac
Download Docker Desktop from the official website.
Your first container: Hello World
docker run hello-world
Docker will download the image, execute it and show you a welcome message.
Magic. You have already run your first container.
Let’s raise something useful: a Nginx server
Ejecuta:
docker run -d -p 8080:80 nginx
-d → in the background
-p 8080:80→ open port 8080 and connect it to port 80 in the container
Now visit:
http://localhost:8080
You’ll see Nginx welcome page. You already have a web server running without installing anything on your PC.
Your first Dockerfile (Level: beginner ninja)
Let’s containerize a small Node.js app.
Structure:
/demo ├─ Dockerfile ├─ package.json └─ index.js
index.js
console.log("Hello from Docker!");
Dockerfile
FROM node:18-alpine WORKDIR /app COPY . . RUN npm install CMD ["node", "index.js"]
Build the image:
docker build -t myapp-node .
Try it
docker run myapp-node
You’ve got your code, isolated and ready to run on any machine in the world.
Docker Compose: the tool that saves you projects
You have multiple services (backend, frontend and database) when you lift them by hand is hell.
You can deploy with a single command using Docker Compose.
docker-compose.yml
version: "3.9" services: web: image: nginx ports: - "8080:80" db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root
Ejecuta todo con:
docker compose up -d
Ya está. Dos servicios funcionando como si nada.
Good practices fast (to become an expert)
Use images alpine to reduce weight
No put secrets in the Dockerfile, use always .env
Use .dockerignore
Save data on volumes, not inside container
Tag your images (:v1, :latest, etc.)
