Skip to main content

What is a Dockerfile?

This article refers to Platform v3.1.0. The current Platform version is v3.2.0.

Overview

A Dockerfile is a text file that lists the instructions Docker uses to build an image. It defines the base image, the application dependencies, the environment configuration, and the command Docker should run when the container starts. By the end of this step you will have built a small "Hello, Docker World!" image from a Dockerfile and run it on your laptop — the foundational skill you will reuse throughout this tutorial to package your own apps for Barbara edge nodes.

Prerequisites

  • Docker installed on your laptop.
  • A text editor (VS Code, Nano, Notepad++, anything you prefer).
  • A terminal — Linux/macOS shell, or PowerShell / cmd on Windows.
Video walkthrough

Watch this step on YouTube: What is a Dockerfile.

Practice — Hello World Docker app

GitHub

The full source for this practice lives at 01_01 Hello World Docker Application.

1. Create a working directory

mkdir 01_01_hello-world-docker
cd 01_01_hello-world-docker
touch Dockerfile

2. Write the Dockerfile

Open Dockerfile in your editor and paste:

# Use an official lightweight Python image as the base
FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the application code to the container
COPY hello.py /app

# Define the command to run the application
CMD ["python", "hello.py"]

What each instruction does:

  1. FROM python:3.9-slim — start from the slim Python 3.9 base image.
  2. WORKDIR /app — set the working directory inside the container.
  3. COPY hello.py /app — copy hello.py from the build context into the container.
  4. CMD ["python", "hello.py"] — the default command that runs when the container starts.

3. Write the application code

Create hello.py next to the Dockerfile:

print("Hello, Docker World!")

4. Build the image

From the same directory:

docker build -t hello-docker .
  • -t hello-docker — tag the image hello-docker.
  • . — use the current directory as the build context.

Confirm the image is there:

docker images

5. Run the container

docker run hello-docker

Expected output:

Hello, Docker World!

6. Clean up (optional)

# List every container (including stopped ones)
docker ps -a

# Remove a stopped container
docker rm <container_id>

# Remove the image
docker rmi hello-docker

Summary

You wrote a Dockerfile, built an image from it, and ran a container locally. This is the foundational skill the rest of the tutorial builds on — every Barbara workload, from a tiny Python service to a full ML stack, starts as a Dockerfile.