Docker for Python Developers (2021 Edition)
Episode Deep Dive
Guest introduction and background
Peter McKee is the Head of Developer Relations at Docker. He’s been a software engineer for many years, starting his journey writing inventory management software before moving on to bigger teams and exploring modern developer tools. Peter’s passion lies in mentoring, teaching, and showing developers how to simplify complex tasks using containers and container orchestration platforms. At Docker, he focuses on educating and supporting developers to harness Docker technologies for building and shipping applications seamlessly.
What to Know If You're New to Python
If you’re just getting started with Python and want to make the most of this Docker-focused conversation, here are some quick tips:
- Understanding virtual environments (
venv
) and package management withpip
can help you grasp how Docker extends these ideas to system-level dependencies. - Basic knowledge of Python’s command-line usage (e.g., running
.py
scripts) will make it easier to translate that workflow into Docker commands. - Familiarize yourself with the concept of isolation (virtual environments in Python vs. container isolation). Docker is basically a system-wide isolation tool, just like
venv
is for Python packages.
Key points and takeaways
- Docker as the Universal Environment Docker helps eliminate the “it works on my machine” problem by packaging applications and dependencies into a single container. This means whether you’re on macOS, Windows, or Linux, you can reliably run the same environment, which drastically simplifies collaboration. Docker images capture not just your Python packages, but also external system-level dependencies, ensuring consistency across dev, test, and prod.
- Links & Tools:
- Simplifying Complex Development with Docker Compose When you have multiple services (e.g., a Python API, database, and a frontend), Docker Compose helps you define and run them together with a single command. Instead of managing manual
docker run
steps, you use a declarative YAML file that lets you configure networks, volumes, and environment variables for all containers at once.- Links & Tools:
- Layered Images and Multi-stage Builds Docker images can be built in layers, making it faster and more efficient to rebuild only what changes. Multi-stage builds let you compile or process large dependencies in an intermediate image, then copy over just the final artifact into a lean production image. This results in smaller, safer images with a minimal attack surface.
- Links & Tools:
- Using Docker in Data Science and Reproducible Research Docker is especially powerful for data science because you can package Python, specialized libraries, and even heavy dependencies (like Fortran or Rust-based libs) in one place. That setup enhances reproducibility: if you share the same container image, you can share the exact environment, making it simpler to confirm your colleagues’ results.
- Security Scanning and Supply Chain Protection Docker Hub integrates vulnerability scanning powered by Snyk to alert you when your base images or dependencies have known security issues. This shift-left mindset ensures developers proactively manage security rather than reacting to problems close to release time. Keeping images small and frequently scanning can greatly reduce risks.
- Links & Tools:
- Kubernetes, Swarm, and Container Orchestration While Docker Compose is sufficient for local development or simpler deployments, Kubernetes is often used at large scale. However, many smaller teams do just fine with Docker alone or Docker Swarm if they only need minimal orchestration. The key takeaway is not to jump directly into Kubernetes without a good reason; simpler solutions can be quite effective for many projects.
- Links & Tools:
- DevOps and Infrastructure as Code in Practice Docker is part of a broader DevOps culture shift, enabling developers to own more of their app’s deployment configuration. You define your environment in a Dockerfile or a Compose file, store it in version control, and treat it like code. This approach simplifies CI/CD pipelines and makes onboarding new developers easier because “spin-up instructions” are captured in code.
- Links & Tools:
- GitHub
- Up and Running with Git (Talk Python course)
- Links & Tools:
- Enriching Local Development with VS Code and PyCharm Visual Studio Code’s Docker plugin, as well as PyCharm’s integrated Docker support, let you manage containers or even run and debug your Python code within Docker. This keeps your local OS clean and helps ensure your app runs consistently in development and production. You can easily switch between local debugging and container-based debugging without changing your code.
- Links & Tools:
- TestContainers and Continuous Testing For Python developers, libraries like
testcontainers-python
provide ephemeral container environments to run integration tests against real services (e.g., Postgres or Redis) rather than mocked interfaces. This leads to more trustworthy tests and speeds up the QA cycle, as the environment is easy to reproduce on any machine or in CI/CD pipelines.- Links & Tools:
- Docker Desktop on Apple M1 (ARM) For folks using Apple Silicon (M1) Macs, Docker has been actively improving native support. Containers can run ARM-compatible images or emulate x86-based images, but you may face partial compatibility issues if an underlying dependency doesn’t provide an ARM build. Docker’s ARM support continues to grow, making M1 use smoother over time.
- Links & Tools:
Interesting quotes and stories
“I was getting paid to learn and write applications. It was awesome.” — Peter McKee on the excitement of transitioning into professional software development.
“Containers let you step into the same OS, the same library versions as everyone else on your team, so you’re not scared of messing up your machine.” — A reflection on how Docker helps unify teams across different operating systems.
“You don’t want to keep pets; you want consumable resources that you replace when there’s an issue.” — An analogy about ephemeral containers versus carefully maintained servers.
Key definitions and terms
- Container: A standardized unit of software that packages code and all dependencies so the application runs quickly and reliably from one environment to another.
- Image: The static, read-only template used to create containers.
- Docker Compose: A tool to define and run multi-container applications with a single YAML file.
- Swarm: Docker’s native container orchestration solution.
- Kubernetes: A powerful open-source system for automating deployment, scaling, and management of containerized applications.
- Multi-stage Build: A Dockerfile feature that lets you use multiple
FROM
statements in one Dockerfile to keep images lean.
Learning resources
Here are some Talk Python courses and resources to further develop your Python and Docker skills. Visit these links to learn more:
- Python for Absolute Beginners: Perfect for those just starting their Python journey.
- Full Web Apps with FastAPI: Learn how to build more comprehensive backend web apps you can easily containerize.
- Modern APIs with FastAPI and Python: Dive into building APIs that seamlessly fit into Docker deployments.
Overall takeaway
Docker is a game-changer for creating consistent environments, streamlining local development, and easing the path to production. From small projects to enterprise solutions, containers help Python developers unify OS-level, third-party, and code dependencies across the entire team. With the combination of Docker Compose, security scanning, multi-stage builds, and powerful orchestration tools, you can boost both reliability and velocity in your workflow. The key is to start simple, focusing on Docker’s core benefits of repeatability and portability, and only expand into advanced tooling—like Kubernetes—when your use case truly demands it.
Links from the show
Peter on Twitter: @pmckee
Docker: docker.com
Docker Roadmap: github.com
It works on my machine certification: codinghorror.com
Test Containers Package: github.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy