Skip to content

Instantly share code, notes, and snippets.

@scyto
Last active May 11, 2025 20:17
Show Gist options
  • Save scyto/642d9fa2b5392b14a5f989c9ff281e34 to your computer and use it in GitHub Desktop.
Save scyto/642d9fa2b5392b14a5f989c9ff281e34 to your computer and use it in GitHub Desktop.

Revisions

  1. scyto revised this gist Oct 3, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions docker-auto-label.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@ This container puts a label on each machine based on a config that matches servi
    If the service is running the label gets a 1 and if the label get as 0 its not running.
    this can be used with constraints to either locate serices on a node with another service OR make sure a service doesn't land on a node with another service

    I would love to find a better version of this that does this without the need for the manual config file (you can use a file bindmount instead of a config if you prefer)

    ## Swarm Consideration
    State is all read-only in a config
    You need this to run on all nodes.
  2. scyto revised this gist Oct 3, 2023. 1 changed file with 22 additions and 3 deletions.
    25 changes: 22 additions & 3 deletions docker-auto-label.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ this can be used with constraints to either locate serices on a node with anothe
    State is all read-only in a config
    You need this to run on all nodes.

    ## Example Stack
    ### Example Stack
    ```
    version: "3.7"
    services:
    @@ -32,7 +32,7 @@ configs:
    ```

    ## Example Config (this is my real one as of writing this)
    ### Example Config (this is my real one as of writing this)
    This is the name of the service when running followed by what you want the label to say
    use `sudo docker service ls` to get the names

    @@ -59,5 +59,24 @@ wordpress_db,running_wordpress_db
    wordpress_wordpress,running_wordpress
    ```

    ## Example of how i use this with adguard to make sure adguard 1 and 2 don't run on the same node EVER (which causes failure conditions)
    ### Example of how i use this with adguard to make sure adguard 1 and 2 don't run on the same node EVER (which causes failure conditions)

    ```
    ...
    adguard2:
    image: 'adguard/adguardhome:latest'
    restart: always
    volumes:
    - work2:/opt/adguardhome/work
    - config2:/opt/adguardhome/conf
    networks:
    - adguard2-mvl
    - adguard_sync
    deploy:
    mode: replicated
    replicas: 1
    placement:
    constraints: [node.labels.running_adguard1 == 0]
    ...
    ```
  3. scyto revised this gist Oct 3, 2023. 1 changed file with 39 additions and 1 deletion.
    40 changes: 39 additions & 1 deletion docker-auto-label.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,14 @@
    # Auto Label

    This container puts a label on each machine based on a config that matches service names.
    If the service is running the label gets a 1 and if the label get as 0 its not running.
    this can be used with constraints to either locate serices on a node with another service OR make sure a service doesn't land on a node with another service

    ## Swarm Consideration
    State is all read-only in a config
    You need this to run on all nodes.

    ## Example Stack
    ```
    version: "3.7"
    services:
    @@ -22,4 +30,34 @@ configs:
    dockerautolabel_config:
    external: true
    ```
    ```

    ## Example Config (this is my real one as of writing this)
    This is the name of the service when running followed by what you want the label to say
    use `sudo docker service ls` to get the names

    ```
    adguard_adguard1,running_adguard1
    adguard_adguard2,running_adguard2
    adguard_adguardhome-sync,running_adguardhome-sync
    agent_agent,running_agent
    apprise_apprise-api,running_apprise-api
    cloudflare-ddns_cloudflare-ddns,running_cloudflare-ddns
    cluodflared_portainer-tunnel,running_portainer-tunnel
    dockerproxy_dockerproxy,running_dockerproxy
    infinitude_infinitude,running_infinitude
    mqtt_mosquitto,running_mosquitto
    npm_app,running_npm
    npm_db,running_npm_db
    oauth_oauth2-proxy,running_oauth2-proxy
    portainer_portainer,running_portainer
    shepherd_shepherd,running_shepherd
    swag_swag,running_swag
    unifiapibrowser_unifiapibrowser,running_unifiapibrowser
    watchtower_watchtower,running_watchtower
    wordpress_db,running_wordpress_db
    wordpress_wordpress,running_wordpress
    ```

    ## Example of how i use this with adguard to make sure adguard 1 and 2 don't run on the same node EVER (which causes failure conditions)

  4. scyto created this gist Oct 3, 2023.
    25 changes: 25 additions & 0 deletions docker-auto-label.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@



    ```
    version: "3.7"
    services:
    dockerautolabel:
    build: .
    image: davideshay/dockerautolabel:latest
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    configs:
    - source: dockerautolabel_config
    target: /config/servicelist.txt
    deploy:
    mode: replicated
    replicas: 1
    placement:
    constraints: [ node.role == manager]
    configs:
    dockerautolabel_config:
    external: true
    ```