Moment 6: Isolated Environments with Docker
Reading time: approx. 12 min
Welcome to the final moment in your journey toward a complete development environment. You have learned to set up specific environments for Python and web development. But you have surely encountered the classic problem in teaching: a student says "but it works on my computer!". Differences in operating systems, installed libraries or settings can make code that works perfectly for you crash for someone else. Docker is the modern solution to exactly this problem.
In this final moment we introduce "containers", a revolutionary way to package an application with all its dependencies in a standardized, isolated unit. Understanding Docker is understanding how modern software is distributed and run, from small projects to gigantic cloud services.
What You Will Learn
After this moment you will:
- Understand what a container is and how it simplifies development and distribution.
- Realize why Docker is such a powerful tool for reproducibility in the classroom.
- Install Docker on your Ubuntu system.
- Run a prebuilt web application in a Docker container.
The Basics: What is a Container?
Think of a regular shipping container. It doesn't matter if it contains bananas, electronics or furniture. The container itself has standardized dimensions and attachments. Therefore any ship, train or crane can handle it, without needing to know anything about the contents.
A Docker container works in exactly the same way for software. It packages:
- Your application code (e.g. your Python script or your website).
- All dependencies (e.g. specific Python libraries or Node.js).
- System libraries and settings required to run the code.
The result is a standardized "box" that is guaranteed to work the same everywhere Docker is installed, on your Ubuntu computer, a student's Windows laptop or a server in the cloud. The problem "it works on my computer" is gone.
Practical Examples: Install Docker and Run Your First Container
1. Install Docker
Installing Docker is a bit more advanced than a regular apt install command, because we want to add Docker's official package sources to always get the latest version. The best guide is always the official one.
- Follow the official instructions for installing Docker Engine on Ubuntu: Docker Docs: Install on Ubuntu.
- IMPORTANT after installation: To avoid having to type
sudobefore every docker command, add your user to thedockergroup. Run this command in the terminal and then log out and in again for the change to take effect.sudo usermod -aG docker $USER
2. Run Your First Container: "Hello World"
The classic test to see that everything works.
docker run hello-world
This command will: download the minimal hello-world image (a template for a container) from the public hub Docker Hub, create a container from it, run it (which prints out a confirmation message) and then exit.
3. Run an Interactive Web Server
Let's do something more useful: run a prebuilt web server in a container.
docker run -d -p 8080:80 docker/getting-started
Let's break down the command:
docker run: Start a container.-d: Run it in "detached mode", that is in the background.-p 8080:80: Publish a port. This maps port 8080 on your computer to port 80 inside the container.docker/getting-started: The name of the image to use.
Now open your browser and go to http://localhost:8080. You will see a website being served from the completely isolated container!
To see which containers are running, type docker ps. To stop it, copy its ID from the ps command and type docker stop <container_id>.
Docker in the Classroom: A Revolution for Teaching
Using Docker in teaching can solve many headaches:
- Perfect reproducibility: You can create a
Dockerfile(a recipe file) for a specific project. Each student then runs the same command and gets an identical environment. No more problems with different library versions or OS-specific errors. - Safe experimentation: Students can experiment freely inside a container without any risk of breaking anything on their own computer.
- Easy access to advanced software: Need a database for a project? Instead of a complicated installation you can run
docker run postgresand have a full-featured database running in seconds.
Course Completion and Your Next Steps
A big and heartfelt CONGRATULATIONS! You have now completed the entire course "Set Up Your Development Environment in Ubuntu". You have gone from installing the system to understanding and using the tools that drive modern software development. You can now manage Python environments, build websites, version control with Git and even package applications with Docker.
What happens now? There is only one answer: Build something! Knowledge is best reinforced through practical application.
- Take the web project you started and build on it.
- Create a new Python project to solve a problem you have in your daily life.
- Explore Docker Hub to see what prebuilt applications you can run with a single command.
You now have an incredibly solid foundation to stand on. The world of open source and development is open to you. Good luck!

