Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Q: Example of connecting to a remote Docker for Windows instance #19

Open
IAmTheDude opened this issue Aug 20, 2019 · 14 comments
Open

Q: Example of connecting to a remote Docker for Windows instance #19

IAmTheDude opened this issue Aug 20, 2019 · 14 comments

Comments

@IAmTheDude
Copy link

Sorry to bother,

If I'm reading it all right, in the Dev branch I can now specify the instance to connect to as a url.

Does this mean I can connect to a remote instance?

If so thats brill as Im using ha-dockermon over REST for my Windows box and other Pis and would be great to get them all into one component for HA.

Do you have an example of how I would connect to say a remote Windows instance ie tcp:// or npipe etc?

I feel like either the component cant do it or Im doing it wrong. Granted I only really know the basics of Docker itself, compose, dockerfile etc and havnt really got that far with remote administration bar Portainer.

Also, great component! Been playing with it since I found it and its brill that you guys are continually working on it!

@ualex73
Copy link
Collaborator

ualex73 commented Aug 23, 2019

In theory the configuration should be:

docker_monitor:
  hosts:
    - url: tcp://127.0.0.1:1234
...

@IAmTheDude
Copy link
Author

Brill, thanks for confirming. I just wanted to make sure it was as simple as that and make sure it wasnt my config for docker_monitor

Turns out there are issues exposing tcp on 'Docker Desktop' (mine is on Windows Server 2019) when using Linux containers. After researching turns out to be a common problem with a lot on convoluted information about workarounds, and to add to the confusion it also worked on older versions of 'Docker for Windows'

I eventually stumbled upon a container that exposes it in a working way (albeit unsecured) but I was able to get docker_monitor working and working well.

I also got it connecting to another Pi instance of Docker. Now that I know it all works I can get it secured!

Ill leave these here in case anyone stumbles on them.

To expose on Windows - Unsecured

version: '3'
services:
  docker-remote-api:
    container_name: docker-remote-api
    image: jarkt/docker-remote-api
    restart: always
    environment:
      - "TZ=$TIMEZONE"
    ports:
      - "$DOCKERAPIPORT:2375"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Secured: kekru/docker-remote-api-tls

HA Config for multiple connections:

docker_monitor:
  hosts:
    - url: unix://var/run/docker.sock
      name: local_docker_on_a_pi
      event: false
      scan_interval: 5
      monitored_conditions:
        - version
      containers:
        portainer:
          switch: true
          sensors:
            - status
    - url: tcp://192.xxx.xxx.xxx:2375
      name: docker_on_windows_using_expose_container
      event: false
      scan_interval: 5
      monitored_conditions:
        - version
      containers:
        portainer:
          switch: true
          sensors:
            - status
    - url: tcp://192.xxx.xxx.xxx:2375
      name: docker_on_another_pi
      event: false
      scan_interval: 5
      monitored_conditions:
        - version
      containers:
        portainer:
          switch: true
          sensors:
            - status

@pergolafabio
Copy link

guys, i am installing this too
i am running hassOS, how do i need to specify the -url option?
it it like tcp://localhost:2375 ?

@GuyKh
Copy link

GuyKh commented Jan 30, 2020

@IAmTheDude @Sanderhuisman - I don't see the hosts option you mentioned anywhere in the code - and when I try to set it up, I get - 2020-01-30 09:24:54 ERROR (MainThread) [homeassistant.config] Invalid config for [docker_monitor]: [hosts] is an invalid option for [docker_monitor]. Check: docker_monitor->docker_monitor->hosts. (See ?, line ?). Please check the docs at https://github.com/Sanderhuisman/docker_monitor

Assistance needed :)

@Kisty
Copy link

Kisty commented Jan 30, 2020

@GuyKh how have you installed the addon? I've had similar issues when trying to use the 0.1.2 version from HACS but switching to master seemed to help. I think the config syntax has changed across the versions. Can you post your config for docker_monitor?

@GuyKh
Copy link

GuyKh commented Jan 30, 2020

@Kisty - I used the master version from this repository.
Look at the example in the README file here (https://github.com/Sanderhuisman/docker_monitor/blob/master/README.md) - the example doesn't include hosts.

I've taken now the version from develop branch - which there the example has the hosts - but I'm afraid to use it since it's not a final version

@Kisty
Copy link

Kisty commented Jan 30, 2020

@GuyKh That's fair, but I think that the documentation isn't up to date, though I might be wrong. Did you try the master branch?

@GuyKh
Copy link

GuyKh commented Jan 30, 2020

@Kisty - I have. That's the one which doesn't work.
It doesn't have the hosts option indeed in the code. (check __init__.py and look for [DOMAIN][HOSTS])

@Kisty
Copy link

Kisty commented Jan 30, 2020

@GuyKh There's no mention of hosts config on the README.md for master. I think you might've been looking at the 0.1.2 version. If you're on the master branch, try url instead.

host = config[DOMAIN].get('url')

If you want to get it working with develop or 0.1.2, then take a look at this issue #23

@GuyKh
Copy link

GuyKh commented Jan 30, 2020

@Kisty - true, you have url indeed - but that's exactly the indication where you have a single URL - not multiple hosts.
That's my point.

You mentioned v 0.1.2 - where can I find it? I don't see a branch or version for it

@Kisty
Copy link

Kisty commented Jan 30, 2020

@GuyKh ah right. So you want multiple hosts? In that case, try 0.1.2. It's a tag btw so you should be able to git checkout 0.1.2.
https://github.com/Sanderhuisman/docker_monitor/tree/0.1.2

@GuyKh
Copy link

GuyKh commented Jan 30, 2020

@Kisty - got it, thanks. It works :)
You too see many printouts in the log?

I've set the event flag to false

2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Running home-assistant
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Running adguard-home
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event

@Kisty
Copy link

Kisty commented Jan 30, 2020

@GuyKh great! Tbh, I couldn't get it working for now as I need to figure out how to mount the docker socket when using HA from Hass.io.

@Giel538
Copy link

Giel538 commented Mar 15, 2020

@Kisty - got it, thanks. It works :)
You too see many printouts in the log?

I've set the event flag to false

2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor pihole event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Running home-assistant
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:02 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor home-assistant event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.helpers] Running adguard-home
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event
2020-01-30 15:09:03 INFO (DockerContainerStats) [custom_components.docker_monitor.sensor] Sensor adguard-home event

i have this problem too.

Also i have scan_interval on 60 but it is still updating every 10 seconds :(

docker_monitor:
  hosts:
    - name: Docker
      event: false     
      scan_interval: '60'      
      url: unix://var/run/docker.sock

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants