Hook
Docker lets you bundle your application and all its dependencies into a single isolated image. That means your code runs the same everywhere without the classic “it works on my machine” headaches.
Problem / Context
Before containers, deploying meant installing various software on each server, handling library versions, and dealing with incompatibilities. The result – environments diverge and releases break.
Why it matters
Containers give you stability, fast scaling, and simplify CI/CD pipelines. You save time on environment setup and reduce the risk of production bugs.
How to do it
- Install Docker Engine
sudo apt‑update sudo apt‑install -y ca-certificates curl gnupg sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo "deb [arch=$(dpkg --print-architecture) signed‑by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt‑update sudo apt‑install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin - Verify the installation
docker run --rm hello-world - Create a Dockerfile for a simple Node.js app:
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . CMD ["node", "index.js"] - Build the image
docker build -t my‑app . - Run the container
Your app is now reachable atdocker run -d -p 3000:3000 --name my‑app‑c my‑apphttp://localhost:3000.
Anti‑patterns
- Running the container as root – create a non‑root user inside the image.
- Skipping
EXPOSE– makes it harder to see which ports are intended. - Using heavyweight base images – prefer Alpine‑based images to keep the size small.
Conclusion / Action plan
- Install Docker on your machine.
- Write a simple Dockerfile for one of your projects.
- Add Docker commands to your CI pipeline.
- After a successful run, explore
docker‑composefor multi‑container setups.