优先级
- docker-compose file
- Shell environment variables
- Environment file
- Dockerfile
- Variable is not defined
export
1
2
|
# 此命令放在 .sh 脚本中时,环境变量仅在执行当前脚本或子脚本时生效
export TAG=2.0.2
|
1
2
3
4
5
6
7
8
|
# docker-compose.yml
version: '3'
services:
test-service:
image: test-service:${TAG}
container_name: test-service
...
|
1
2
|
# 执行 docker-compose up -d 时会读取 TAG 为 2.0.2
docker-compose up -d
|
.env
在 docker-compose.yml 文件同级目录下创建 .env 文件
1
2
3
4
5
6
7
8
|
# docker-compose.yml
version: '3'
services:
test-service:
image: test-service:${TAG}
container_name: test-service
...
|
1
2
|
# 执行 docker-compose up -d 时,会将 ${TAG} 替换为 .env 中的 2.0.2
docker-compose up -d
|
Enviroment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# docker-compose.yml
version: '3'
services:
data-tag-biz:
image: 192.168.1.XX/xxxx/data-standard-biz:9.0
network_mode: "host"
restart: always
ports:
- 10015:9015
environment:
- NACOS-HOST=${NACOS_HOST}
- SW_NAME=test:${SV_NAME}
- SW_SERVICES=192.168.1.XX:11800
- TRACK=-javaagent:/opt/skywalking-agent.jar
- JAVA_OPTS=-Xms512m -Xmx1024m -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC
container_name: data-standard-biz-9
|
dockerfile
1
2
3
4
|
ENV NODE_VERSION 7.2.0
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc"
|