Hey everyone! I'm working on a backend API application using Python with FastAPI, Alembic, Pydantic, and SQLAlchemy. I'm currently figuring out my Docker workflow and I'm torn between creating a single multistage Dockerfile that serves both development (with features like hot reloading and development tools such as ruff) and production (with optimizations like a non-root user and minimal image size) or creating separate Dockerfiles for each scenario. I'm really interested in hearing what's considered best practice here. Thanks!
3 Answers
I think it's better to make the Docker image environment-agnostic and just provide environment configurations at runtime. That way, your production image won't get bogged down with unnecessary dev dependencies like formatters or linters.
I recommend creating two Dockerfiles. The first one can be a multistage build that sets up a base image along with local development tools, while the second can be dedicated to production. This way, any shared components can go into the base image, and both dev and prod can build on top of that without cluttering their own setups.
This approach definitely helps avoid the "it works on dev!" problem. If you do forget to make a change in the prod environment, it could lead to issues. I've actually created a dev image based on the production image so that it inherits everything while allowing me to add the necessary development tools.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String