DEV Community

Bhaskar Sharma
Bhaskar Sharma

Posted on

πŸš€ Day 9 of My DevOps Journey: Dockerfiles & Image Building

Hello dev.to community! πŸ‘‹

Yesterday, I explored Docker Networking & Volumes β€” the backbone of connecting containers and persisting data. Today, I’m diving into Dockerfiles & Image Building β€” the magic that turns source code into lightweight, portable containers. 🐳

πŸ”Ή Why Dockerfiles Matter

A Dockerfile is like a recipe 🍳 that defines how to build a Docker image.

Automates app packaging.

Ensures consistency across environments.

Forms the base for CI/CD pipelines.

In DevOps, mastering Dockerfiles means you can containerize any app reliably.

🧠 Core Concepts I’m Learning
πŸ“¦ Dockerfile Basics

FROM β†’ base image (e.g., FROM python:3.10-slim)

WORKDIR β†’ working directory inside container

COPY β†’ copy files into image

RUN β†’ run commands (install dependencies, etc.)

CMD / ENTRYPOINT β†’ define how container starts

πŸ”§ Example: Simple Node.js App

Dockerfile

Use Node.js base image

FROM node:18-alpine

Set working directory

WORKDIR /app

Copy package.json & install dependencies

COPY package*.json ./

RUN npm install

Copy app source

COPY . .

Expose port

EXPOSE 3000

Start app

CMD ["npm", "start"]

Build & Run

Build image

docker build -t mynodeapp .

Run container

docker run -p 3000:3000 mynodeapp

πŸ› οΈ Mini Use Cases in DevOps

Build microservices into portable images.

Standardize CI/CD builds across environments.

Reduce β€œworks on my machine” problems.

⚑ Pro Tips

Keep images small β†’ use alpine base images.

Use .dockerignore to skip unnecessary files.

Minimize RUN layers (combine commands with &&).

Tag images properly (myapp:v1.0.0 vs. latest).

πŸ§ͺ Hands-on Mini-Lab (Try this!)

1️⃣ Write a Dockerfile for a Python Flask app.
2️⃣ Build the image β†’ docker build -t flaskapp .
3️⃣ Run the container β†’ docker run -p 5000:5000 flaskapp
4️⃣ Open http://localhost:5000 πŸŽ‰

🎯 Key Takeaway

Dockerfiles turn your app into a portable, repeatable container image β€” a must-have skill for DevOps engineers before diving into CI/CD.

πŸ”œ Tomorrow (Day 10)
I’ll explore Docker Compose β€” running multi-container apps with ease.

πŸ”– #Docker #DevOps #Containers #CICD #DevOpsJourney #CloudNative #Automation #SRE #OpenSource

Top comments (0)