aboutsummaryrefslogtreecommitdiffstats
path: root/docker_net.py
blob: dd6f7058e4c387139f98f83291bd4e0379faaecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
import docker
import os

def get_mqtt_addr():
    if os.getuid() != 0:
        raise Exception("You must be root to access the docker API and fetch the container's network")

    client = docker.from_env()
    containers = client.networks.get("poweredagay_default").attrs["Containers"]
    for k, v in containers.items():
        if "mqtt_1" in v["Name"]:
            return v["IPv4Address"].split("/")