docker-compose.yml文件使用变量参数和定义容器的环境变量

docker-compose 专栏收录该内容
1 篇文章 0 订阅

docker-compose.yml文件使用变量参数:

jasper@jasper-S1200RP:~/test/testcompose$ cat docker-compose.yml
  version: '3.7'   
  services:     
      appshield:      
            build:        
                context: .
                args:          
                    VER: ${APPSHIELD_VER}
            image: nginx:${APPSHIELD_VER}  
     
            restart: always
            container_name: engine_appshield       
            hostname: engine_appshield       
            privileged: true       
jasper@jasper-S1200RP:~/test/testcompose$ cat .env
APPSHIELD_VER=latest

检查变量是否生效:

jasper@jasper-S1200RP:~/test/testcompose$ docker-compose config
services:
  appshield:
    build:
      args:
        VER: latest
      context: /home/jasper/test/testcompose
    container_name: engine_appshield
    hostname: engine_appshield
    image: nginx:latest
    privileged: true
    restart: always
version: '3.7'

docker-compose.yml定义容器的环境变量 env_file:

jasper@jasper-S1200RP:~/test/testcompose$ cat docker-compose.yml
  version: '3.7'   
  services:     
      appshield:      
            build:        
                context: ./
                args:          
                    VER: ${APPSHIELD_VER}
            image: nginx:${APPSHIELD_VER}       
            restart: always
            container_name: engine_appshield       
            hostname: engine_appshield       
            privileged: true
            env_file:
              - ./env/common.env

jasper@jasper-S1200RP:~/test/testcompose$ mkdir env
jasper@jasper-S1200RP:~/test/testcompose$ vim env/common.env

jasper@jasper-S1200RP:~/test/testcompose$ cat env/common.env
JAVA_HOME=/usr/local/java


检测环境变量是否生效:

jasper@jasper-S1200RP:~/test/testcompose$ docker-compose config
services:
  appshield:
    build:
      args:
        VER: latest
      context: /home/jasper/test/testcompose
    container_name: engine_appshield
    environment:
      JAVA_HOME: /usr/local/java

    hostname: engine_appshield
    image: nginx:latest
    privileged: true
    restart: always
version: '3.7'

 

 

  • 1
    点赞
  • 0
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值