Fallback for environment variables with docker-compose

僤鯓⒐⒋嵵緔 提交于 2020-12-30 06:57:26

问题


Given the following configuration:

mysql:
    environment:
        MY_MYSQL_PORT:
    image: mysql
    ports:
        - "${MY_MYSQL_PORT}:3306"

There's a way to provide a fallback value for MY_MYSQL_PORT without relying on wrapper scripts? I already tested like bash ${MY_MYSQL_PORT-3306} but it doesn't work.


回答1:


They implemented that feature with compose 1.9 release:

Added support for shell-style inline defaults in variable interpolation.

The supported forms are ${FOO-default} (fall back if FOO is unset) and ${FOO:-default} (fall back if FOO is unset or empty).

Release Notes Docker Compose 1.9



来源:https://stackoverflow.com/questions/33784730/fallback-for-environment-variables-with-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!