There are two articles describing using environment variable but my use case is different.
I have docker-compose file where I have 3-7 containers. Depends on situation.
version: '2'
services:
db:
image: example/db
backend:
image: example/server
frontend:
image: example/gui
Now, in above example all my images will use latest version, but I would like to control which version to deploy, therefore I want to define some variable version and use it in all my images, something like:
version: '2'
variable version=1.0.1
services:
db:
image: example/db:$version
backend:
image: example/server:$version
frontend:
image: example/gui:$version
Second example is wrong, but it shows my need what I want to achieve
Docker-compose used Interpolation Syntax ${variable}
for variables and you missed that in your file.
version: '2'
services:
db:
image: example/db:${version}
backend:
image: example/server:${version}
frontend:
image: example/gui:${version}
So just pass the version to your docker-compose
command
version=1.13-alpine docker-compose up
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.