Purpose
Create and setup a python development environment inside of docker in 5 minutes. (Also more or less a journal to myself of how t...
For further actions, you may consider blocking this person and/or reporting abuse
In the first code example you create a virtual environment but do not activate it. This would result in you installing fastapi and hypercorn into the system python which is probably not what you wanted.
Aye, you're right. Thanks for pointing that out.
Don't you mean "source .venv/bin/activate", not "source .venv/bin/python"?
A couple of further minor points - your (optional?) "EXPOSE 8005" line should be "8000", shouldn't it? There's also a typo in the "docker-compose" line where you have "buid" rather than "build".
This is a game-changer! Using Docker for Python development is a brilliant idea. This setup will streamline workflows and ensure consistency across environments. A must-try for any Python development services!
Ok, makes sense now. Thanks for the feedback :)
Glad I could help. I will try to make the post a little more clear about that, I can see from the title now that it's kind of misleading.
Why create a venv inside a container? I mean your python environment is already isolated by the container, why introduce a not needed layer of abstraction? Just curious :)
You're not actually setting up a virtual environment inside the container. The container ultimately ends up being your end product. You can write your code and build your container and push it to the cloud/your server/github/dockerhub etc. It effectively sets up a CICD workflow. I will try to make this clearer in the post above but if you look at the Dockerfile you're not actually setting up a virtual environment inside the container. The only thing you do inside the container is install the required modules for your app to run and updating your codebase. Once your push that container to your server for example it can be live. No need to setup any kind of environments on your server it's all containerized.
Thanks this was helpful.
Great walkthrough! This blog clearly explains how to set up a FastAPI development environment with Docker in just minutes. The step-by-step approach—covering virtual environments, Dockerfile, docker-compose, and bind mounts—makes it beginner-friendly yet practical. The helper scripts and troubleshooting tips are especially useful for smooth DevOps workflows.