Many Docker tutorials immediately introduce Docker Compose, Kubernetes, networking, volumes, and multi-container applications.
For beginners, that can feel overwhelming.
In this article, we'll build a very small Docker image that runs a simple Python script. The goal is to understand the core Docker concepts before moving on to more advanced containerization topics.
By the end of this tutorial, you'll understand:
- What Docker is
- What a container is
- How Docker images work
- How to build an image
- How to run a container
- The difference between an image and a container
Why Docker?
One common problem in software development is:
"It works on my machine."
An application may work perfectly on a developer's computer but fail on another machine because of missing libraries, different operating systems, or incompatible software versions.
Docker solves this problem by packaging:
- Application code
- Runtime
- Libraries
- Dependencies
- Configuration
into a single portable unit called a container.
As long as Docker is installed, the application can run consistently across environments.
Docker in Simple Terms
A useful analogy is:
Docker Image = Blueprint
Docker Container = House Built From The Blueprint
An image is a template.
A container is a running instance created from that image.
You can create multiple containers from the same image.
Installing Docker on Ubuntu
Update package information:
sudo apt update
Install Docker:
sudo apt install docker.io
Verify the installation:
sudo docker run hello-world
You should see a welcome message from Docker.
Running Docker Without sudo
Add your user to the Docker group:
sudo usermod -aG docker $USER
Log out and log back in.
Now Docker commands can be executed without sudo.
Environment
The following environment was used:
Ubuntu 24.04 LTS
Docker 29.1.3
Python 3.x
Project Structure
docker-python-app/
│
├── test.py
└── Dockerfile
Our Tiny Python Application
Create:
test.py
Contents:
print("This is a test")
Normally, the script can be executed using:
python3 test.py
Now we'll run the same application inside a Docker container.
Creating a Dockerfile
Create a file named:
Dockerfile
Contents:
FROM ubuntu:latest
WORKDIR /docker-apps
COPY ./test.py .
RUN apt update && apt install python3 -y
CMD ["python3", "./test.py"]
Docker builds images layer by layer by processing each instruction in the Dockerfile from top to bottom.
Let's understand each instruction.
FROM
FROM ubuntu:latest
Uses Ubuntu as the base image.
WORKDIR
WORKDIR /docker-apps
Sets the working directory inside the container.
COPY
COPY ./test.py .
Copies the Python script into the container.
RUN
RUN apt update && apt install python3 -y
Installs Python inside the image.
CMD
CMD ["python3", "./test.py"]
Specifies the command executed when the container starts.
Building the Docker Image
Build the image:
docker build -t ubuntu-python .
Docker reads the Dockerfile and creates an image named:
ubuntu-python
Verify:
docker images
You should see the newly created image.
Running the Container
Create and start a container:
docker run -it -d --name test-container ubuntu-python
Verify:
docker ps -a
View container logs:
docker logs test-container
Expected output:
This is a test
Congratulations! You have successfully executed a Python application inside a Docker container.
Docker Workflow
test.py
↓
Dockerfile
↓
docker build
↓
Docker Image
↓
docker run
↓
Docker Container
↓
This is a test
This same workflow is used for much larger applications.
Image vs Container
One of the most important Docker concepts is understanding the difference between an image and a container.
Image
An image is:
- Read-only
- A template
- Used to create containers
Example:
ubuntu-python
Container
A container is:
- Running or stopped
- Created from an image
- The actual execution environment
Example:
test-container
A single image can create many containers.
Useful Docker Commands
Stop a container:
docker stop <container_name_or_id>
Remove a container:
docker rm <container_name_or_id>
Force remove a container:
docker rm -f <container_name_or_id>
Remove all stopped containers:
docker container prune
List images:
docker images
List containers:
docker ps -a
The Most Important Lesson
One of the biggest misconceptions among beginners is that Docker is a virtual machine.
It is not.
Containers share the host operating system kernel, making them much lighter and faster than traditional virtual machines.
Docker packages applications and their dependencies in a portable and isolated way without requiring a full guest operating system.
Understanding this distinction is one of the key concepts in containerization.
💡 Key Takeaway
Docker does not replace your application.
Docker packages your application together with its runtime and dependencies so it can run consistently across different environments.
Understanding the difference between an image and a container is one of the most important Docker concepts.
Future Enhancements
Once comfortable with this example, you can explore:
- Docker volumes
- Docker networking
- Docker Compose
- Multi-container applications
- Docker Hub
- Jenkins + Docker integration
- Kubernetes
The concepts learned in this article form the foundation for all of them.
Final Thoughts
Docker can seem intimidating when first encountered through large production deployments.
Starting with a tiny application makes the learning process much easier.
A simple Python script is enough to understand:
- Images
- Containers
- Dockerfiles
- Build process
- Container execution
Once these fundamentals become clear, moving toward real-world containerized applications becomes much more natural.
If you're new to Docker, try building this example yourself before moving on to Docker Compose, Kubernetes, or cloud deployments. The concepts learned here will transfer directly to larger containerized systems.

Top comments (0)