【发布时间】:2016-09-09 14:51:59
【问题描述】:
我正在使用 docker compose 来运行我的应用程序。为此,我需要在容器内设置主机(这取决于我正在运行的环境)。
我的做法是:
创建环境文件并设置变量:
#application.env
SERVER_IP=10.10.9.134
我的 docker compose 文件如下所示:
version: '2'
services:
api:
container_name: myApplication
env_file:
- application.env
build: ./myApplication/
entrypoint: ./docker/api-startup.sh
ports:
- "8080:8080"
depends_on:
- redis
extra_hosts: &extra_hosts
myip: $SERVER_IP
但我的问题是变量 SERVER_IP 永远不会被替换。
当我运行 docker-compose config 时,我看到:
services:
api:
build:
context: /...../myApplication
container_name: myApplication
depends_on:
- redis
entrypoint: ./docker/api-startup.sh
environment:
SERVER_IP: 10.10.9.134
extra_hosts:
myip: ''
ports:
- 8080:8080
我尝试使用 $SERVER_IP 或 ${SERVER_IP} 替换变量引用,但没有成功。
【问题讨论】:
标签: docker docker-compose