Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Docker labels for services #61

Closed
modem7 opened this issue Sep 5, 2022 · 13 comments
Closed

[Feature Request] Docker labels for services #61

modem7 opened this issue Sep 5, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@modem7
Copy link
Contributor

modem7 commented Sep 5, 2022

Would it be possible to use compose file labels to define the Docker services side of things?

E.g.

  homepage:
    image: ghcr.io/benphelps/homepage:latest
    container_name: Homepage
    labels: 
      ## Homepage Dashboard
      - homepage.name=Netboot.XYZ
      - homepage.category=System
      - homepage.url=192.168.0.6:3000
      - homepage.icon=https://raw.githubusercontent.com/modem7/MiscAssets/master/Icons/HeimdallIcons/netboot.png
    ports:
      - 8045:3000
    volumes:
      - $USERDIR/Homepage:/app/config
      - /var/run/docker.sock:/var/run/docker.sock # (optional) For docker integrations

URL should be optional, as the URL should be able to be grabbed from the Docker socket link.

I have a similar setup with the Flame dashboard, which gives the following (with Traefik integration):
image

This would reduce the amount of dependency on external config files, and allow for auto-updating of services when they are added/remove/modified.

@benphelps
Copy link
Member

It's a good idea and has been suggested before, it'll just take some careful planning to make sure it's reliable and flexible enough.

@benphelps benphelps changed the title [FEATURE REQUEST] - Docker labels for services [Feature Request] Docker labels for services Sep 5, 2022
@benphelps benphelps added the enhancement New feature or request label Sep 6, 2022
@benphelps
Copy link
Member

So I've made some progress on this, and it seems to be working :)

As an example, here are the labels for my Emby docker compose entry:

emby:
  labels:
    - traefik.enable=true
    - traefik.http.routers.emby.rule=Host(`emby.media.home`)
    - traefik.http.routers.emby.entrypoints=web
    - homepage.group=Media
    - homepage.name=Emby
    - homepage.icon=emby.png
    - homepage.href=http://emby.media.home
    - homepage.description=Media server
    - homepage.widget.type=emby
    - homepage.widget.url=http://emby.media.home
    - homepage.widget.key=myembyapikeywashere

This essentially defines a services.yaml entry equivalent to:

- Media:
    - Emby:
        icon: emby.png
        href:
        description: Media server
        server: phelpsrv-b
        container: emby
        widget:
          type: emby
          url: http://emby.media.home
          key: myembyapikeywashere

But... and theres always a but.

This needs to work alongside entries in services.yaml, and with that, you lose support for strictly defined ordering. You're basically leaving this up to the Docker API and the order that it sends back the containers. The current logic is to place discovered entries above the hard configured entries. But ordering between discovered entries in the same group comes down to the Docker APIs response.

Adding support for configured positions could be done, but would require even more refactoring, so if it is done, it'll be done at a later time.

@modem7
Copy link
Contributor Author

modem7 commented Sep 9, 2022

Hell yea! Great job!

Tbf, at least for me, but I know I don't speak for the larger userbase, the automated ordering (maybe a way to do it alphabetically would be the simplest choice, rather than some custom solution), can certainly be done at a later date, and wouldn't/couldn't be considered critical by any means.

@benphelps
Copy link
Member

Just pushed the changes, I wanted to do a latest release before this bigger change to allow for some end-user testing before releasing it.

You can check out the commit here: d66326b

@just5ky
Copy link

just5ky commented Sep 10, 2022

I noticed that :latest does not have this feature, so i pulled :main and it worked

i don't know what i am doing wrong with Portainer API.

image

if i enable Portainer API label, I'm getting NextJS error when checked from console.

    labels:
      - "homepage.group=Admin"
      - "homepage.name=portainer"
      - "homepage.icon=portainer.png"
      - "homepage.href=http://192.168.0.151:9000"
      - "homepage.description=Docker management"
      - "homepage.widget.type=portainer"
      - "homepage.widget.url=http://192.168.0.151:9000"
      - "homepage.widget.key=API_KEY"
    Listening on port 3000
    (node:1) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    [
      500,
      Error: socket hang up
          at connResetException (node:internal/errors:711:14)
          at Socket.socketOnEnd (node:_http_client:518:23)
          at Socket.emit (node:events:525:35)
          at endReadableNT (node:internal/streams/readable:1359:12)
          at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
        code: 'ECONNRESET'
      }
    ]

image

EDIT: Got portainer to work.

had to pass
- "homepage.widget.env=1" label

@benphelps
Copy link
Member

benphelps commented Sep 10, 2022

Yeah, you'll need to pull the main tag, as it hasn't been released yet on the latest tag.

@just5ky
Copy link

just5ky commented Sep 10, 2022

Yeah, you'll need to pull the main tag, as it hasn't been released yet on the latest tag.

Yeah i got it working.
Everything is working as expected

@benphelps
Copy link
Member

Fantastic, hopefully this will be in the latest tag soon.

@benphelps
Copy link
Member

This has been released now :)

@croneter
Copy link

croneter commented Jan 13, 2023

@benphelps This is great!! Still missing documentation though on https://gethomepage.dev correct? I only accidentally stumbled over this feature.

@benphelps
Copy link
Member

@benphelps This is great!! Still missing documentation though on https://gethomepage.dev correct? I only accidentally stumbled over this feature.

https://gethomepage.dev/en/configs/docker/#automatic-service-discovery

@chrisguen
Copy link

Is there a way to automatically get the IP from the docker API and define the port manually in the config? That would be great for internal services.

Copy link
Contributor

github-actions bot commented Feb 5, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants