0
0
Dockerdevops~30 mins

Development container patterns in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Development Container Patterns
📖 Scenario: You are working on a software project and want to create a development environment that is consistent for everyone on your team. Using a development container helps by packaging all the tools and dependencies inside a container.This project will guide you through creating a simple Dockerfile for a development container, adding configuration, running a command inside the container, and finally displaying the result.
🎯 Goal: Build a Docker development container that installs Python 3.12, sets a working directory, and runs a simple Python script inside the container.
📋 What You'll Learn
Create a Dockerfile with a base image of Python 3.12
Set the working directory inside the container to /app
Add a Python script named hello.py that prints 'Hello from container!'
Run the Python script inside the container and display the output
💡 Why This Matters
🌍 Real World
Development containers help teams work with the same tools and dependencies, avoiding the 'it works on my machine' problem.
💼 Career
Knowing how to create and use development containers is a key skill for DevOps engineers and developers to ensure consistent environments and smooth collaboration.
Progress0 / 4 steps
1
Create the Dockerfile with base image
Create a file named Dockerfile and write a line to use the base image python:3.12-slim.
Docker
Need a hint?

The first line in a Dockerfile usually starts with FROM followed by the base image name.

2
Set working directory and add Python script
In the Dockerfile, add a line to set the working directory to /app. Then create a file named hello.py with the exact content print('Hello from container!').
Docker
Need a hint?

Use WORKDIR /app to set the directory inside the container. The Python script should have exactly one line printing the message.

3
Add command to run Python script
In the Dockerfile, add a line to run the Python script hello.py using the command python hello.py when the container starts.
Docker
Need a hint?

Use CMD ["python", "hello.py"] to run the script when the container starts.

4
Build and run the container to see output
Build the Docker image with the tag dev-container and run it. Write the command to build the image and then the command to run the container so it prints Hello from container!.
Docker
Need a hint?

Use docker build -t dev-container . to build and docker run --rm dev-container to run the container and see the output.