Search code examples
dockergitlab-citraefik

how to pass Gitlab CI variable as a Traefik traefik.http.routers.container_name.rule label value


In Gitlab CI I'm trying to set Traefik labels while building an image in order to register it in the Traefik Service. This is how it's done:

- docker build -t $IMAGE . --label traefik.http.routers.$SERVICE_NAME.rule="Host(`$SERVICE_URL`)" --label traefik.enable=true

and this is how it is interpreted:

Step 7/7 : LABEL traefik.http.routers.socialmedia-service-master.rule=Host()
 ---> Running in c67fe595032a

both $SERVICE_URL and $SERVICE_NAME definitely set. How can I make it working?


Solution

  • Try escaping the back ticks, like so:

    docker build -t $IMAGE . --label traefik.http.routers.$SERVICE_NAME.rule="Host(\`$SERVICE_URL\`)" --label traefik.enable=true