Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Live Coding: Refactoring Docker Related Files in a FastAPI App

live-coding-refactoring-docker-related-files-in-a-fastapi-app.jpg

This is a live coding video that goes over how I tackle Dockerizing a project without any prior experience with FastAPI.

Quick Jump:

I’m starting a new project with a friend and just for fun we decided to try FastAPI out since it’s a fairly small API back-end and we wanted to see what FastAPI is all about.

Neither of us have any experience with it, but she started the app off using a boilerplate project that was found on GitHub. In this video I go over changing around pretty much all of the Docker related files and also learn a bit about FastAPI along the way.

There’s no cuts in this video, it was recorded as I did the work for the first time. Since I was doing the work anyways, it felt like a good spot to record a video around how I go about learning new things in real-time.

# Live Demo

Timestamps

  • 0:40 – I only built the original Docker image beforehand
  • 1:40 – Upping the project and fixing a FastAPI validation error
  • 4:24 – Checking out what the app does in a browser and curl
  • 6:56 – Trying out a few FastAPI config experiments
  • 9:29 – Investigating the Dockerfile
  • 14:24 – Pulling in a new Dockerfile from my example Flask app
  • 17:30 – Getting the latest versions of each Python dependency
  • 19:29 – Copying over new .gitignore and .dockerignore files
  • 21:35 – Creating a new docker-compose.yml file
  • 24:45 – Creating a new .env file
  • 30:26 – Iterating quickly on our uvicorn CMD with docker-compose exec
  • 36:15 – Removing the reference to .env in the FastAPI settings
  • 38:04 – Fixing “empty reply from server” by binding to 0.0.0.0 not 127.0.0.1
  • 39:31 – Double checking if our env variables and volumes work
  • 43:00 – Trying to get a config file to work with uvicorn directly
  • 49:55 – Loading uvicorn through gunicorn as a worker type
  • 57:37 – Moving all of our ad-hoc gunicorn flags into a config file
  • 1:00:04 – Does it actually work? What about certain config options?
  • 1:03:45 – Creating a new branch and committing our changes
  • 1:04:16 – Swapping PROJECT_NAME to use our existing COMPOSE_PROJECT_NAME
  • 1:07:49 – Checking out the auto-generated OpenAPI documentation
  • 1:08:33 – Reviewing our changes and addressing the SERVER_NAME
  • 1:14:34 – Setting the SECRET_KEY another time and finishing things up
  • 1:18:59 – Any questions?

Reference Links

What would you have done differently? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments