{"id":139395,"date":"2022-11-02T13:30:56","date_gmt":"2022-11-02T17:30:56","guid":{"rendered":"https:\/\/blog.logrocket.com\/?p=139395"},"modified":"2024-06-04T17:03:16","modified_gmt":"2024-06-04T21:03:16","slug":"using-fastapi-inside-docker-containers","status":"publish","type":"post","link":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/","title":{"rendered":"Using FastAPI inside Docker containers"},"content":{"rendered":"<!DOCTYPE html>\n<html><p>FastAPI is a web framework for building APIs with Python \u2265v3.6 that is based on standard Python-type hints. What makes FastAPI stand out is its focus on modern Python, high performance, and ease of use. But, you might be wondering how Docker containers come into the FastAPI conversation.<\/p><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"487\" src=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Fast API Docker Containers\" srcset=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png 730w, https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers-300x200.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\">\n<p>Imagine that you\u2019re building a REST API and you need to use PostgreSQL, Redis, Celery, RabbitMQ, and a bunch of other dependencies. The first problem you\u2019d run into is configuring all those dependencies on your machine. This setup process could be a hassle, however, there is another, more pressing problem.<\/p>\n<p>What if you\u2019re developing on Linux, but your colleague develops on Windows? You have to keep in mind that some dependencies that work well on Linux don\u2019t work well on Windows. And even if you somehow manage to get past the development phase, what if your development environment isn\u2019t consistent with your deployment environment? All these problems sum up to one thing, portability.<\/p>\n<p>To make your project more portable, you could develop in an isolated environment that has the project code and all the dependencies installed, which is exactly what Docker containers does.<\/p>\n<p>Docker isn\u2019t exclusive to FastAPI; <a href=\"https:\/\/blog.logrocket.com\/dockerizing-django-app\/\">we can use Docker to containerize most projects<\/a> regardless of what languages or frameworks are used. In this article, we\u2019ll learn how to containerize a FastAPI application with Docker.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>Familiarity with the basics of Python and FastAPI<\/li>\n<li>Familiarity with the basics of Docker<\/li>\n<li>Python \u2265v3.7<\/li>\n<li>Python <a href=\"https:\/\/pypi.org\/project\/pip\/\">Pip<\/a>, the package manager<\/li>\n<li><a href=\"https:\/\/www.docker.com\/\">Docker<\/a> installed on your machine<\/li>\n<\/ul>\n<h2 id=\"tableofcontents\">Table of contents<\/h2>\n<ul>\n<li><a href=\"#setting-up-development-environment\">Setting up our development environment<\/a><\/li>\n<li><a href=\"#adding-python-code\">Adding the Python code<\/a><\/li>\n<li><a href=\"#dockerizing-fastapi-application\">Dockerizing our FastAPI application<\/a><\/li>\n<li><a href=\"#docker-container\">Docker container<\/a><\/li>\n<li><a href=\"#docker-image\">Docker image<\/a><\/li>\n<li><a href=\"#writing-our-dockerfile\">Writing our Dockerfile<\/a><\/li>\n<li><a href=\"#building-docker-image-dockerfile\">Building the Docker image from our Dockerfile<\/a><\/li>\n<li><a href=\"#running-container-docker-image\">Running the container from our Docker image<\/a><\/li>\n<li><a href=\"#next-steps\">Next steps<\/a><\/li>\n<\/ul>\n<h2 id=\"setting-up-development-environment\">Setting up our development environment<\/h2>\n<p>Let\u2019s create a rudimentary FastAPI application with one endpoint that returns a list of users.<\/p>\n<p>To create a virtual environment, run <code>python3 -m venv env-name<\/code> on Unix and macOS or <code>python -m venv env-name<\/code> on Windows. Replace <code>env-name<\/code> with the name you chose for your virtual environment.<\/p>\n<p>To activate the virtual environment, run <code>source env-name\/bin\/activate<\/code> on Unix and macOS or <code>.\\\\env-name\\\\Scripts\\\\activate<\/code> on Windows.<\/p>\n<p>In the directory where you want to start your project, run <code>mkdir demo_app<\/code>, which will create a new folder called <code>demo_app<\/code> in that directory:<\/p>\n<ul>\n<li>Run <code>cd demo_app<\/code><\/li>\n<li>Run <code>pip install fastapi[all]<\/code><\/li>\n<li>Run <code>pip freeze &gt; requirements.txt<\/code> to create a requirements file in the <code>demo_app<\/code> folder with all the installed dependencies<\/li>\n<\/ul>\n<h2 id=\"adding-python-code\">Adding the Python code<\/h2>\n<p>Launch the <code>demo_app<\/code> folder in the IDE of your choice. Create a file called <code>demo_app\/\\[main.py\\](&lt;http:\/\/main.py&gt;)<\/code> and add the snippet below into the <code>main.py<\/code> file:<\/p>\n<pre class=\"language-python hljs\">from fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"\/\")\nasync def root():\n    return {\"message\": \"Hello World\"}\n\n@app.get(\"\/users\")\nasync def users():\n    users = [\n        {\n            \"name\": \"Mars Kule\",\n            \"age\": 25,\n            \"city\": \"Lagos, Nigeria\"\n        },\n\n        {\n            \"name\": \"Mercury Lume\",\n            \"age\": 23,\n            \"city\": \"Abuja, Nigeria\"\n        },\n\n         {\n            \"name\": \"Jupiter Dume\",\n            \"age\": 30,\n            \"city\": \"Kaduna, Nigeria\"\n        }\n    ]\n\n    return users\n<\/pre>\n<p>We created two endpoints, one returns \u201cHello, World!\u201d and the second, <code>\/users<\/code>, returns a dummy list of users. Next, run <code>uvicorn main:app --reload<\/code> to start your FastAPI application.<\/p>\n<p>Point your browser to <code>[http:\/\/127.0.0.1:8000](&lt;http:\/\/127.0.0.1:8000\/&gt;)\/docs<\/code>. You should see the two endpoints we just added documented:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-139408 size-full\" src=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-default-endpoints.png\" alt=\"Fast API Default Endpoints\" width=\"730\" height=\"236\" srcset=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-default-endpoints.png 730w, https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-default-endpoints-300x97.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>To test the endpoint, point your browser to <code>\\[http:\/\/127.0.0.1:8000\\](&lt;http:\/\/127.0.0.1:8000\/&gt;)\/users<\/code>. It should return the dummy list of users, as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-139411 size-full\" src=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/test-fastapi-endpoint-dummy-user-list.png\" alt=\"Test Fastapi Endpoint Dummy User List\" width=\"730\" height=\"125\" srcset=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/test-fastapi-endpoint-dummy-user-list.png 730w, https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/test-fastapi-endpoint-dummy-user-list-300x51.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>Now, <a href=\"https:\/\/blog.logrocket.com\/building-a-graphql-server-with-fastapi\/\">we have a basic FastAPI application<\/a>, but to improve the development experience, we can eliminate the need to create a virtual environment and install the project dependencies manually. This optimization would handle what dependencies to install, where to install them, and how to install them when porting our project to other platforms. Let\u2019s learn how to do this with Docker.<\/p>\n<h2 id=\"dockerizing-fastapi-application\">Dockerizing our FastAPI application<\/h2>\n<p>By running the project inside a Docker container, we can eliminate the need to create a virtual environment and having to install project dependencies manually.<\/p>\n<h2 id=\"docker-container\">Docker container<\/h2>\n<p>You can think of a Docker container as a small computer that runs on another computer. Essentially, a Docker container is just an isolated environment on some machine that contains a project\u2019s code and its dependencies.<\/p>\n<p>When we containerize or dockerize our FastAPI application, we are essentially creating a lightweight virtual box with our project\u2019s dependencies installed and our FastAPI code configured to run. As a result, anyone with our virtual box could run our application without having to deal with the low-level project configuration logistics.<\/p>\n<p>Most importantly, we could simply upload this virtual-box to our staging or production server to make our application go live without having to add a lot of configuration.<\/p>\n<h2 id=\"docker-image\">Docker image<\/h2>\n<p>In our example, what we share with other people or deploy to our servers is not the container or virtual-box itself, but the manual for creating the container. You probably already know this manual as the Docker image.<\/p>\n<p>A Docker image contains step-by-step instructions for building a container. Containers are spun from images during the build step. But, to <a href=\"https:\/\/blog.logrocket.com\/node-js-docker-improve-dx-docker-compose\/#dockerize-app-docker-multi-stage-build\">create a Docker image<\/a>, we first need to write a Docker file.<\/p>\n<p>To containerize our FastAPI application, we need to follow three steps:<\/p>\n<ol>\n<li>Write a Dockerfile<\/li>\n<li>Build a Docker image from our Dockerfile<\/li>\n<li>Spin up a container from the Docker image we built<\/li>\n<\/ol>\n<p>Let\u2019s explore each step further.<\/p>\n<h2 id=\"writing-our-dockerfile\">Writing our Dockerfile<\/h2>\n<p>Create a <code>demo_app\/Dockerfile<\/code> file and add the code snippet below:<\/p>\n<pre class=\"language-python hljs\">FROM python:3-slim-buster\n\nRUN mkdir \/code\n\nWORKDIR \/code\n\nCOPY requirements.txt .\n\nRUN pip install -r requirements.txt\n\nCOPY . .\n\nCMD [\"uvicorn\", \"main:app\", \"--host=0.0.0.0\", \"--port=80\"]\n<\/pre>\n<p>We populated our Dockerfile with a set of instructions that the Docker daemon would follow chronologically to build our image when issued the command.<\/p>\n<p>When you install Docker, it automatically installs the Docker client, which accepts Docker commands in your terminal and the Docker daemon. Think of the Docker daemon as Docker\u2019s backend, the main entity that processes commands received by the Docker client.<\/p>\n<p>Let\u2019s make sense of what each command in our Dockerfile above means. The <code>FROM<\/code> instruction sets the official Python image as the base. It instructs the Docker daemon to build our image on top of an existing image. Docker adopts this layered approach to enhance reusability.<\/p>\n<p><code>RUN mkdir \/code<\/code> creates a <code>code<\/code> directory in the image when it is built and eventually the container when it is created.<\/p>\n<p>The <code>WORKDIR<\/code> instruction sets the default working directory to the newly created <code>\/code<\/code> directory. This working directory will be applicable to any subsequent <code>COPY<\/code>, <code>ADD<\/code>, <code>RUN<\/code>, and <code>CMD<\/code> instructions.<\/p>\n<p>The first <code>COPY<\/code> instruction adds the <code>requirements.txt<\/code> file to the current working directory. The <code>RUN<\/code> instruction executes the <code>pip install -r requirements.txt<\/code> command. This command would install the dependencies listed in the requirements file in our container.<\/p>\n<p>The second <code>COPY<\/code> instruction copies the rest of the content from the current directory <code>.<\/code> of the host filesystem to the working directory <code>.<\/code> inside the image and eventually the container. Lastly, the <code>CMD<\/code> instruction sets the command for running our application\u2019s server published on <code>port 8080<\/code>.<\/p>\n<h2 id=\"building-docker-image-dockerfile\">Building the Docker image from our Dockerfile<\/h2>\n<p>Go to your <code>demo_app<\/code> directory in your terminal and then run the following command:<\/p>\n<pre class=\"language-python hljs\">docker image build --tag demo-app-image .\n<\/pre>\n<p>To build our image, the Docker daemon needs a few pieces of information. For one, it needs the name of the <code>Dockerfile<\/code> to use. If this isn\u2019t passed, Docker looks for a file named <code>Dockerfile<\/code> in the working directory. If you name your file anything other than <code>Dockerfile<\/code>, then you must pass the name of the file using the <code>--file<\/code> option:<\/p>\n<pre class=\"language-python hljs\">docker image build --file custom-docker-file-name --tag demo-app-image\n<\/pre>\n<p>Docker also needs the build context. The build context is the directory that\u2019s accessible to Docker during the build process. In our case, we specified the current working directory as the build context with <code>.<\/code>.<\/p>\n<p>If the image build was successful, you should get an output similar to the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-139413 size-full\" src=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/image-build-successful-output.png\" alt=\"Image Build Successful Output\" width=\"730\" height=\"233\" srcset=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/image-build-successful-output.png 730w, https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/image-build-successful-output-300x96.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>At this point, you should have an image called <code>demo-app-image<\/code> on your machine. You can run the <code>docker image ls<\/code> command to see a list of all the images you\u2019ve created or pulled to your local machine from the registry.<\/p>\n<h2 id=\"running-container-docker-image\">Running the container from our Docker image<\/h2>\n<p>Run the command below to spin up a container from our <code>demo-app-image<\/code>:<\/p>\n<pre class=\"language-python hljs\">docker container run --publish 80:80 --name demo-app-container demo-app-image\n<\/pre>\n<p>The <code>--name<\/code> option creates a container with the name <code>demo-app-container<\/code> that is based on the <code>demo-app-image<\/code>. The <code>--publish<\/code> option forwards requests coming through <code>port 8080<\/code> on our local machine to <code>port 8080<\/code> in our container.<\/p>\n<p>If the command works, you should get the following output in your terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-139416 size-full\" src=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/command-works-output.png\" alt=\"Command Works Output\" width=\"730\" height=\"57\" srcset=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/command-works-output.png 730w, https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/command-works-output-300x23.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>You can point your browser to <code>[http:\/\/localhost:80\/docs](http:\/\/localhost\/docs)<\/code> to visit the documentation page. You can also test the <code>\/users<\/code> endpoint. That\u2019s it!<\/p>\n<h2 id=\"next-steps\">Next steps<\/h2>\n<p>Docker containers make our projects more portable. Remember that what we share with other people or push to our deployment environment isn\u2019t the container itself, but the image. Usually, we share an image by publishing it to a public registry like the <a href=\"https:\/\/hub.docker.com\/\">Docker Hub<\/a>.<\/p>\n<p>However, it\u2019s not always the case that we\u2019d want our image to be publicly available. In that case, we could push our Dockerfile along with the project code and have other members of the team build the image and run the container on their end.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this article, we\u2019ve learned how to simplify locally setting up a FastAPI project or deploying to a staging or production environment with Docker containers.<\/p>\n<p>Fundamentally, a Docker container creates a virtual-box-like isolated environment that bundles our application code with its dependencies. As a result, it\u2019s easier to deploy our application anywhere without having to worry about platform-specific inconsistencies.<\/p>\n<p>To containerize a FastAPI application or just any application with Docker, first, we need to add a Dockerfile to the project, build an image from the Dockerfile, and run a container from the image. While Docker is the most popular containerization technology out there, it\u2019s not the only one.<\/p>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>To containerize a FastAPI application with Docker, first, we need to add a Dockerfile to the project, build an image from the Dockerfile, and run a container from the image.<\/p>\n","protected":false},"author":156415957,"featured_media":139405,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2147999,1],"tags":[2109732,2109833],"class_list":["post-139395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-uncategorized","tag-docker","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using FastAPI inside Docker containers - LogRocket Blog<\/title>\n<meta name=\"description\" content=\"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using FastAPI inside Docker containers - LogRocket Blog\" \/>\n<meta property=\"og:description\" content=\"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/\" \/>\n<meta property=\"og:site_name\" content=\"LogRocket Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-02T17:30:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-04T21:03:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png\" \/>\n\t<meta property=\"og:image:width\" content=\"730\" \/>\n\t<meta property=\"og:image:height\" content=\"487\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nyior Clement\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nyior Clement\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/\",\"url\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/\",\"name\":\"Using FastAPI inside Docker containers - LogRocket Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.logrocket.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png\",\"datePublished\":\"2022-11-02T17:30:56+00:00\",\"dateModified\":\"2024-06-04T21:03:16+00:00\",\"author\":{\"@id\":\"https:\/\/blog.logrocket.com\/#\/schema\/person\/e58856a3346af5d3cf79fd4ea5605ada\"},\"description\":\"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage\",\"url\":\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png\",\"contentUrl\":\"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png\",\"width\":730,\"height\":487,\"caption\":\"Fast API Docker Containers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.logrocket.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using FastAPI inside Docker containers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.logrocket.com\/#website\",\"url\":\"https:\/\/blog.logrocket.com\/\",\"name\":\"LogRocket Blog\",\"description\":\"Resources to Help Product Teams Ship Amazing Digital Experiences\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.logrocket.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.logrocket.com\/#\/schema\/person\/e58856a3346af5d3cf79fd4ea5605ada\",\"name\":\"Nyior Clement\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.logrocket.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e2e6319eb383dfd1e042877a60a7c2ae7fc0be354eb722b6b49a100df8a9ae43?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e2e6319eb383dfd1e042877a60a7c2ae7fc0be354eb722b6b49a100df8a9ae43?s=96&d=mm&r=g\",\"caption\":\"Nyior Clement\"},\"description\":\"I'm an all around software engineer who codes, writes, and sometimes designs. If you want to talk Python, I'm your guy. I own this poky corner of the interwebs xD.\",\"sameAs\":[\"https:\/\/github.com\/Nyior\"],\"url\":\"https:\/\/blog.logrocket.com\/author\/nyiorclement\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using FastAPI inside Docker containers - LogRocket Blog","description":"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/","og_locale":"en_US","og_type":"article","og_title":"Using FastAPI inside Docker containers - LogRocket Blog","og_description":"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.","og_url":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/","og_site_name":"LogRocket Blog","article_published_time":"2022-11-02T17:30:56+00:00","article_modified_time":"2024-06-04T21:03:16+00:00","og_image":[{"width":730,"height":487,"url":"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png","type":"image\/png"}],"author":"Nyior Clement","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nyior Clement","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/","url":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/","name":"Using FastAPI inside Docker containers - LogRocket Blog","isPartOf":{"@id":"https:\/\/blog.logrocket.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage"},"image":{"@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png","datePublished":"2022-11-02T17:30:56+00:00","dateModified":"2024-06-04T21:03:16+00:00","author":{"@id":"https:\/\/blog.logrocket.com\/#\/schema\/person\/e58856a3346af5d3cf79fd4ea5605ada"},"description":"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.","breadcrumb":{"@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#primaryimage","url":"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png","contentUrl":"https:\/\/blog.logrocket.com\/wp-content\/uploads\/2022\/10\/fast-api-docker-containers.png","width":730,"height":487,"caption":"Fast API Docker Containers"},{"@type":"BreadcrumbList","@id":"https:\/\/blog.logrocket.com\/using-fastapi-inside-docker-containers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.logrocket.com\/"},{"@type":"ListItem","position":2,"name":"Using FastAPI inside Docker containers"}]},{"@type":"WebSite","@id":"https:\/\/blog.logrocket.com\/#website","url":"https:\/\/blog.logrocket.com\/","name":"LogRocket Blog","description":"Resources to Help Product Teams Ship Amazing Digital Experiences","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.logrocket.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.logrocket.com\/#\/schema\/person\/e58856a3346af5d3cf79fd4ea5605ada","name":"Nyior Clement","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.logrocket.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e2e6319eb383dfd1e042877a60a7c2ae7fc0be354eb722b6b49a100df8a9ae43?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e2e6319eb383dfd1e042877a60a7c2ae7fc0be354eb722b6b49a100df8a9ae43?s=96&d=mm&r=g","caption":"Nyior Clement"},"description":"I'm an all around software engineer who codes, writes, and sometimes designs. If you want to talk Python, I'm your guy. I own this poky corner of the interwebs xD.","sameAs":["https:\/\/github.com\/Nyior"],"url":"https:\/\/blog.logrocket.com\/author\/nyiorclement\/"}]}},"yoast_description":"Simplify setting up a FastAPI project locally or deploying to a staging or production environment with Docker containers.","_links":{"self":[{"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/posts\/139395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/users\/156415957"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/comments?post=139395"}],"version-history":[{"count":15,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/posts\/139395\/revisions"}],"predecessor-version":[{"id":140316,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/posts\/139395\/revisions\/140316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/media\/139405"}],"wp:attachment":[{"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/media?parent=139395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/categories?post=139395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.logrocket.com\/wp-json\/wp\/v2\/tags?post=139395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}