I have a couple of basic conceptual question regarding the environments of a webapp.
I am trying to build a dockerized Rails app, having: test, development, staging and production.
- My first question is, should the Dockerfile and docker-compose be the same for every environment?
The only thing that would change then would be that when I want to do the testing I pass the RAILS_ENV=test when creating a container, when I want to do the development I pass RAILS_ENV=development and so on.
Would this be the correct idea behind it?
Or can they be different (in my case I am building nginx on production together with app and db but I have just a simple setup with only the app and db for testing and development)
- My second question is, when I pass the RAILS_ENV=test for example, should I do it on the Dockerfile (conditionally pass a different environment when building the image):
# Set environment
ARG BUILD_DEVELOPMENT
# if --build-arg BUILD_DEVELOPMENT=1, set RAILS_ENV to 'development' or set to null otherwise.
ENV RAILS_ENV=${BUILD_DEVELOPMENT:+development}
# if RAILS_ENV is null, set it to 'production' (or leave as is otherwise).
ENV RAILS_ENV=${RAILS_ENV:-production}
Or keep the same image and pass the RAILS_ENV when doing the docker-compose ? :
docker-compose -f docker-compose.production.yml run rake db:create db:migrate RAILS_ENV=production
Thank you!