Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

traefik - Put variable into docker label

maybe is a stupid question...but it's possibile to put variable into docker labels of docker-compose.yml file?

my .env file:

HOST_1=www.example.com
HOST_2=www.site.com

into my docker-compose.yml file can you write like this?

services:
  site_01:
    ...
    labels:
      - "traefik.http.routers.site_01.rule=Host(`${HOST_1}`)"
      - "traefik.http.services.site_01.loadbalancer.server.port=80"

  site_02:
    ...
    labels:
      - "traefik.http.routers.site_02.rule=Host(`${HOST_2}`)"
      - "traefik.http.services.site_02.loadbalancer.server.port=80"

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes it is possible and your snippet seem correct. You can check if the labels are there with docker inspect <container_name_or_id>.

It is also possible to add labels at the build stage. The syntax is the same but labels: key must be under build: key.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...