🧱 Basic Anatomy of a Dockerfile

Kishan Arava
Kishan Arava
|
Published on 22 Mar 2025

# 1. Base Image
FROM python:3.10-slim

# 2. Metadata (optional)
LABEL maintainer="you@example.com"
LABEL version="1.0"

# 3. Set working directory inside the container
WORKDIR /app

# 4. Copy files into the container
COPY requirements.txt .

# 5. Run a command (e.g., install dependencies)
RUN pip install -r requirements.txt

# 6. Copy the rest of the app
COPY . .

# 7. Environment variables (optional)
ENV ENVIRONMENT=production

# 8. Port to expose (optional, mainly for documentation)
EXPOSE 8000

# 9. Default command to run when the container starts
CMD ["python", "main.py"]

🔍 Line-by-Line Explanation

Command

Purpose

FROM

Specifies the base image. Every Docker image starts from a base. Could be ubuntu, node, python, etc.

LABEL

Adds metadata. Not required but helps identify or manage images.

WORKDIR

Sets the working directory inside the container. All subsequent commands will run from here.

COPY

Copies files/folders from your local machine into the container.

RUN

Executes commands at build time, e.g., install dependencies. Each RUN creates a new image layer.

ENV

Sets environment variables. Useful for configuration.

EXPOSE

Declares what port the app runs on. Optional but informative.

CMD

The default command to run when the container starts. Only one CMD is allowed per Dockerfile (the last one used wins).

Powered by wisp

Related Posts
The Easiest Way to Make Perfect, Easy-to-Peel Boiled Eggs

The Easiest Way to Make Perfect, Easy-to-Peel Boiled Eggs

Learn how to make perfectly boiled eggs with an easy-to-follow method that ensures the shells peel off effortlessly every time.

Read Full Story
How to Nail Product-Market Fit Before Diving Into Growth Hacking

How to Nail Product-Market Fit Before Diving Into Growth Hacking

Discover why achieving Product-Market Fit (PMF) is crucial before launching marketing or growth hacking strategies. Learn how to gather essential data, build the right product, assess PMF, and prepare for sustainable growth. This guide breaks down actionable steps to avoid common startup pitfalls and ensure long-term success.

Read Full Story
Buckle Up for Ultralearning: Master Skills at Warp Speed

Buckle Up for Ultralearning: Master Skills at Warp Speed

Discover how to master new skills rapidly and effectively with Scott H. Young’s “Ultralearning.” Explore nine key principles, learn why it matters, and find out how to apply this focused strategy for faster, deeper, and more resilient learning—without wasting time on outdated methods.

Read Full Story
Which fats make the cut?

Which fats make the cut?

Explore the different types of fats, their chemical structures, health benefits and risks, and discover which fats to include in your diet for optimal health.

Read Full Story
© Atomiclearner. 2025