Answer the question
In order to leave comments, you need to log in
What is the easiest way to build docker containers for different env?
Good day.
You need to build the project differently for different env (prod, dev). The project is built via docker-compose (there are several containers).
I read on the Internet, someone suggests simply naming the dockerfile differently and specifying the one you need explicitly via -f, someone suggests creating a shell script to encapsulate the installation logic and call it inside the dockerfile, but no one has written how to do it so that:
- there was a .env file
- when running docker-compose up, this file was read, ENV was taken from there
- depending on ENV, docker-compose.{env}.yaml and dockerfile.{env} were selected for each of the containers (if the assembly is from a directory, and not from image)
At the same time, I would like to avoid bicycles with shell scripts and the like. Docker, on the other hand, should provide something out of the box - it seems to be a standard Wishlist, not so much, but I didn’t find how to do it, and apparently, there will be a fierce crutch.
Is it possible to achieve the above, and if so, how? If not, what method of building a project for different environments would you recommend?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
- depending on ENV, docker-compose.{env}.yaml and dockerfile.{env} were selected for each of the containers (if the build is from a directory, not from an image)
docker build --build-arg ENV=stage .
If you prefer to use separate files for each env, then as far as I understand it is very simple:
1) ENV=xxxx
2) COMPOSE_FILE=docker-compose-$ENV.yml (or $ENV/docker-compose.yml)
3) DOCKERFILE= Dockerfile-$ENV.yml
and run build
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question