]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add note in Docker docs about ensuring graceful shutdowns and lifespan events with...
authorGPla <36087062+GPla@users.noreply.github.com>
Sat, 24 Aug 2024 20:04:30 +0000 (22:04 +0200)
committerGitHub <noreply@github.com>
Sat, 24 Aug 2024 20:04:30 +0000 (20:04 +0000)
Co-authored-by: svlandeg <svlandeg@github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
docs/en/docs/deployment/docker.md

index 253e25fe5d9cbd21c1deb2dd2ea2135d6c41c793..ab1c2201fc7893bed83b27c39597d1f148af2a11 100644 (file)
@@ -232,6 +232,38 @@ Review what each line does by clicking each number bubble in the code. đꑆ
 
 ///
 
+/// warning
+
+Make sure to **always** use the **exec form** of the `CMD` instruction, as explained below.
+
+///
+
+#### Use `CMD` - Exec Form
+
+The <a href="https://docs.docker.com/reference/dockerfile/#cmd" class="external-link" target="_blank">`CMD`</a> Docker instruction can be written using two forms:
+
+âś… **Exec** form:
+
+```Dockerfile
+# âś… Do this
+CMD ["fastapi", "run", "app/main.py", "--port", "80"]
+```
+
+⛔️ **Shell** form:
+
+```Dockerfile
+# â›”️ Don't do this
+CMD fastapi run app/main.py --port 80
+```
+
+Make sure to always use the **exec** form to ensure that FastAPI can shutdown gracefully and [lifespan events](../advanced/events.md){.internal-link target=_blank} are triggered.
+
+You can read more about it in the <a href="https://docs.docker.com/reference/dockerfile/#shell-and-exec-form" class="external-link" target="_blank">Docker docs for shell and exec form</a>.
+
+This can be quite noticeable when using `docker compose`. See this Docker Compose FAQ section for more technical details: <a href="https://docs.docker.com/compose/faq/#why-do-my-services-take-10-seconds-to-recreate-or-stop" class="external-link" target="_blank">Why do my services take 10 seconds to recreate or stop?</a>.
+
+#### Directory Structure
+
 You should now have a directory structure like:
 
 ```