Adding labels to HA's containers?

I don’t suppose there’s a way I can add labels to the hassio containers?

Docker gives you the ability to assign labels via --label flag in order allow me to exclude these in some of my container management tools.

To be specific: in order to include/exclude containers within Watchtower, I need to add a com.centurylinklabs.watchtower.[enable|disable] label to my containers.

You should be able to label them, unless you are referring to the hassio containers.

This. I’m referring to the hassio containers.

They appear to be guid’s, I don’t think you’d want to change them. It could break the functionality. I’m only speculating though.

Docker labels are arbitrary additions you can supply either via LABEL within the Dockerfile or --label at the time of startup. They have no significant meaning on their own.

I don’t you’re looking at the right “label.”

The current hassio containers do not have labels. I guess this would mean we cannot add a label to the containers.

If that’s the case, I believe you answered your own question. There’s no way to name or adjust labels for hassio during creation as home assistant creates the container for you.

I could see this being a nice enhancement in general but the idea behind hassio is that the user doesn’t even need to know about containers.

psst:

or --label at the time of startup.

:wink:

Then why you asking the question if you know how to do it?

hassio_supervisor manages the startup up of the hassio containers, including addons. If there was something it would be within hassio_supervisor.

I throw out a random question by chance hassio_supervior might actually have a --label hook I hadn’t found (yet).

Guess not. :frowning:

You can attempt to use portainer to shutdown an restart the container with your own --label. I don’t know if the label will persist if you were to restart the container with the UI or in general.

The code is available to check these things.

If you don’t see a way to accomplish what you want, you can submit a feature request.

It won’t. Tried that. The networking also messed up, since the services have very specific networking requirements. It seems the hassio containers hard-code their network ip addresses. Modifying the containers outside of supervisor modified their ip addresses and broke everything… whoops!

Thanks, @flamingm0e. I’ll submit a feature request. I would be a nice feature for container management.

The idea behind hassio is that you don’t manage it. LOL.

Seems like you could simply change this

        # Create & Run container
        docker_container = self.sys_docker.run(
            self.image,
            version=self.addon.version,
            name=self.name,
            hostname=self.addon.hostname,
            detach=True,
            init=True,
            privileged=self.full_access,
            ipc_mode=self.ipc,
            stdin_open=self.addon.with_stdin,
            network_mode=self.network_mode,
            pid_mode=self.pid_mode,
            ports=self.ports,
            extra_hosts=self.network_mapping,
            devices=self.devices,
            cap_add=self.addon.privileged,
            security_opt=self.security_opt,
            environment=self.environment,
            volumes=self.volumes,
            tmpfs=self.tmpfs,
        )

to this

        # Create & Run container
        docker_container = self.sys_docker.run(
            self.image,
            version=self.addon.version,
            name=self.name,
            hostname=self.addon.hostname,
            detach=True,
            init=True,
            privileged=self.full_access,
            ipc_mode=self.ipc,
            stdin_open=self.addon.with_stdin,
            network_mode=self.network_mode,
            pid_mode=self.pid_mode,
            ports=self.ports,
            extra_hosts=self.network_mapping,
            devices=self.devices,
            cap_add=self.addon.privileged,
            security_opt=self.security_opt,
            environment=self.environment,
            volumes=self.volumes,
            tmpfs=self.tmpfs,
            label=self.name
        )

I’m not sure if self.name is the correct name though. It appears to be the name of the container. Either way, this is the section you’d be adding it to.

EDIT: Nevermind, It would might require more changes to the sys_docker.run command

1 Like