Should I Use One Dockerfile or Two for Dev and Prod?

0
1
Asked By TechNerd88 On

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

Answered By CodeCrafter123 On

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.

Answered By DockerDude42 On

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.

Answered By DevGuru99 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.