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

What if wireguard is also running in docker #58

Closed
logopk opened this issue May 17, 2021 · 7 comments
Closed

What if wireguard is also running in docker #58

logopk opened this issue May 17, 2021 · 7 comments

Comments

@logopk
Copy link

logopk commented May 17, 2021

My setup is running wireguard in a docker container managed with docker-compose

version: "2.1"
services:
  wireguard:
    image: ghcr.io/linuxserver/wireguard
    container_name: wireguard
    hostname: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    dns:
      - <mydns>
    dns_search: <mydomain>
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Berlin
      - SERVERURL=mydomain #optional
      - SERVERPORT=51820 #optional
      - PEERS=2 #optional
      - PEERDNS=<mydns> #optional
      - INTERNAL_SUBNET=10.13.13.0 #optional
      - ALLOWEDIPS=0.0.0.0/0 #optional
    volumes:
      - wireguard_data:/config
      - /lib/modules:/lib/modules
    ports:
      - 51820:51820/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped
    networks:
      - default
 ...

Apparently the wg-interfaces are not available on the host, so your container isn't reading them.

Any suggestions how to fix this?

Peter

@jr0dd
Copy link

jr0dd commented Jul 6, 2021

I am also curious about this. I'm running a standalone wireguard pod in my k8s cluster. It would be nice to be able to monitor with this exporter

@logopk
Copy link
Author

logopk commented Jul 6, 2021

My solution as for now is a multi stage build (mine has also the complexity to build the exporter for arm)...
so you may just copy the binary from the docker image mindflavor/prometheus-wireguard-exporter
Dockerfile:

FROM ghcr.io/linuxserver/wireguard as wireguard

FROM wireguard

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
RUN ~/.cargo/bin/cargo install prometheus_wireguard_exporter
RUN cp /root/.cargo/bin/prometheus_wireguard_exporter /

WORKDIR /
# copy runscript in
#
COPY /root /

EXPOSE 9586/tcp

root/etc/services.d/prometheus_wireguard_exporter/run:

#!/usr/bin/with-contenv bash
exec /prometheus_wireguard_exporter -n /config/wg0.conf

@qdm12
Copy link
Contributor

qdm12 commented Jul 7, 2021

@logopk not solving the issue, but #63 should take care of cross building the images for all ARM architectures, so you should now be able to just

COPY --from=MindFlavor/prometheus_wireguard_exporter /usr/local/bin/prometheus_wireguard_exporter /usr/local/bin/

to your image for it to work, without having to compile anything. You might want to subscribe to #48 to get updates on that.

@logopk
Copy link
Author

logopk commented Jul 7, 2021

Thank you @qdm12 that’s great.

@qdm12
Copy link
Contributor

qdm12 commented Jul 7, 2021

@logopk you can try now with:

COPY --from=mindflavor/prometheus-wireguard-exporter:multi-arch-dockerfile /usr/local/bin/prometheus_wireguard_exporter /usr/local/bin/

and it should work 👍

Regarding the actual issue, anyone has tried to run the exporter with --network="container:wireguard"? I'm pretty sure that should work. You would then have to publish the prometheus metric port on the wireguard container, but at least your containers would be separated.

@tomsteenbakkers
Copy link

tomsteenbakkers commented Oct 13, 2021

I have tried --network="container:wireguard" but no result. Wireguard is running in a docker and Wireguard-exporter also. But it looks like Wireguard-exporter can not access the log, I can access the metrics using http://localhost:9586/metrics but it shows no data

Both containers are running in the same stack.

Any suggestions?

This is the docker-compose file I'm using.

version: '3.6'
services:

  wireguard:
    container_name: wireguard
    image: ghcr.io/linuxserver/wireguard
    restart: unless-stopped
    environment:
    - PUID=1000
    - PGID=1000
    - TZ=Etc/UTC
    - SERVERURL=<secret>
    - SERVERPORT=51820
    - PEERS=<secret>
    - PEERDNS=auto
    - ALLOWEDIPS=0.0.0.0/0
    ports:
    - "51820:51820/udp"
    volumes:
    - /home/pi/IOTstack/volumes/wireguard:/config
    - /lib/modules:/lib/modules:ro
    cap_add:
    - NET_ADMIN
    - SYS_MODULE
    sysctls:
    - net.ipv4.conf.all.src_valid_mark=1
    
  prometheus-wireguard-exporter:
    network_mode: host
    container_name: wgexporter
    restart: unless-stopped
    image: mindflavor/prometheus-wireguard-exporter
    volumes:
    - /home/pi/IOTstack/volumes/wireguard:/config
    - /lib/modules:/lib/modules:ro
    cap_add:
    - NET_ADMIN
    

@Pandaaaa906
Copy link

PROMETHEUS_WIREGUARD_EXPORTER_PREPEND_SUDO_ENABLED=true

after adding this env it worked

I have tried --network="container:wireguard" but no result. Wireguard is running in a docker and Wireguard-exporter also. But it looks like Wireguard-exporter can not access the log, I can access the metrics using http://localhost:9586/metrics but it shows no data

Both containers are running in the same stack.

Any suggestions?

This is the docker-compose file I'm using.

version: '3.6'
services:

  wireguard:
    container_name: wireguard
    image: ghcr.io/linuxserver/wireguard
    restart: unless-stopped
    environment:
    - PUID=1000
    - PGID=1000
    - TZ=Etc/UTC
    - SERVERURL=<secret>
    - SERVERPORT=51820
    - PEERS=<secret>
    - PEERDNS=auto
    - ALLOWEDIPS=0.0.0.0/0
    ports:
    - "51820:51820/udp"
    volumes:
    - /home/pi/IOTstack/volumes/wireguard:/config
    - /lib/modules:/lib/modules:ro
    cap_add:
    - NET_ADMIN
    - SYS_MODULE
    sysctls:
    - net.ipv4.conf.all.src_valid_mark=1
    
  prometheus-wireguard-exporter:
    network_mode: host
    container_name: wgexporter
    restart: unless-stopped
    image: mindflavor/prometheus-wireguard-exporter
    volumes:
    - /home/pi/IOTstack/volumes/wireguard:/config
    - /lib/modules:/lib/modules:ro
    cap_add:
    - NET_ADMIN
    

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

No branches or pull requests

6 participants