I'm working on overriding default docker-compose.yml
file using docker-compose.override.yml
as shown in this link, And I can able to specify ports
and volumes
in the override file.
In the similar way, is it also possible to specify version of the image which needs to be deployed? If no, what is the best way to handle such circumstance where we need to specify different version for the image?
Any help on this would be great.
There is (now?) a better option for what you want to do. From https://docs.docker.com/compose/environment-variables/
It’s possible to use environment variables in your shell to populate values inside a Compose file:
web:
image: "webapp:${TAG}"
Docker is already having that feature. I tried to override image name with simple docker-compose, it is working.
For example,
docker-compose.yml
with content,
my-httpd:
image: httpd:latest
ports:
- "1110:80"
And docker-compose.override.yml
with content,
my-httpd:
image: httpd:2.4
After the execution of docker-compose -d
, here is the docker ps info,
It uses ports
from docker-compose.yml
(not overrided) and image
from docker-compose.override.yml
as it is getting overridden here.
Note: It you have different names and location, you could use it like the following command instead of docker-compose -d
,
docker-compose -f <DOCKER COMPOSE LOCATION> -f <OVERRIDE FILE LOCATION> up -d
Edit 2:
Overriding in the above manner will only replace the non array values and the array variables will be merged.
For example, if I have ports
in both files which is an array, it will bind both the ports instead of taking ports value just from the overriding file unlike the image
part (non array).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With