在docker compose中使用环境变量在环境部分中不起作用

时间:2020-06-26 02:29:34

标签: docker-compose

我想在所有主机中使用一个docker compose文件,该文件需要设置主机名。

例如

version: '3.7'

services:
  watchtower:
    image: containrrr/watchtower
    container_name: watchtower
    hostname: ${HOSTNAME}
    domainname: home.foo.net
    restart: unless-stopped
    environment:
      - TZ=America/Los_Angeles
      - WATCHTOWER_NOTIFICATIONS=email
      - WATCHTOWER_NOTIFICATION_EMAIL_FROM=logs@foo.com
      - WATCHTOWER_NOTIFICATION_EMAIL_TO=logs@foo.com
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.home.foo.net
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=25
      - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
      - WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG=${HOSTNAME}
      - WATCHTOWER_CLEANUP=true
      - WATCHTOWER_INCLUDE_STOPPED=true
      - WATCHTOWER_TIMEOUT=60
      - WATCHTOWER_SCHEDULE=0 0 2 * * *
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    network_mode: host

当我使用相同的撰写文件时,我需要主题告诉我哪个服务器正在发送监视塔消息,因此我将主题设置为包括主机名。

这适用于容器主机名,但是环境变量WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG为空。

是否可以使用环境变量来构建组合环境变量?

0 个答案:

没有答案