Reputation: 109
I've built a simple Docker Compose project as a development environment. I have PHP-FPM, Nginx, MongoDB, and Code containers.
Now I want to automate the process and deploy to production.
The docker-compose.yml
can be extended and can define multiple environments. See https://docs.docker.com/compose/extends/ for more information.
However, there are Dockerfiles for my containers. And for the dev environment are needed more packages than in production.
The main question is should I use separate dockerfiles for dev
and prod
and manage them in docker-compose.yml
and production.yml
?
Separate dockerfiles are easy approach but there is code duplication.
The other solution is to use environment variables and somehow handle them from bash script (maybe as entrypoint ?).
I am searching for other ideas.
Upvotes: 4
Views: 3626
Reputation: 228
In this situation it might be worth considering using an "onbuild" image to handle the commonalities among environments, then using separate images to handle the specifics. Some official images have onbuild versions, e.g., Node. Or you can create your own.
Upvotes: 0
Reputation: 2130
If the packages needed for development aren't too heavy (i.e. the image size isn't significally bigger) you could just create Dockerfile
s that include all the components and then decide whether to activate them based on the value of an environment variable in the entrypoint.
That way you would could have the main docker-compose.yml
providing the production environment while development.yml
would just add the correct environment variable value where needed.
Upvotes: 1
Reputation: 867
In docker-compose
version >= 1.5.0 you can use environment variables, may be this suits you?
Upvotes: 1
Reputation: 12402
According to the official docs:
... you’ll probably want to define a separate Compose file, say
production.yml
, which specifies production-appropriate configuration.Note: The
extends
keyword is useful for maintaining multiple Compose files which re-use common services without having to manually copy and paste.
Upvotes: 1