Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding image version in docker-compose file

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.

like image 271
Stranger Avatar asked May 09 '16 08:05

Stranger


2 Answers

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}"
like image 154
kwerle Avatar answered Oct 12 '22 04:10

kwerle


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,

enter image description here

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).

like image 25
Stranger Avatar answered Oct 12 '22 04:10

Stranger