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

Running Caddy Docker Proxy on host networking #432

Open
PixelHir opened this issue Nov 29, 2022 · 5 comments
Open

Running Caddy Docker Proxy on host networking #432

PixelHir opened this issue Nov 29, 2022 · 5 comments

Comments

@PixelHir
Copy link

Hi, is it possible to run caddy-docker-proxy on host networking so I don't need to assign it to same networks as the containers? I used to do that with traefik and wanted to replicate this on cdp but I'm encountering problems as below:

image
I've setup a basic whoami container for testing purposes, but I am unable to access it

I'm able to access the said container from the host network
image

My docker compose:
image

@OnigamiSama
Copy link

Hello,

I run mine in network mode host for a few weeks and everything seems to work fine with this docker-compose.yml

services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    container_name: caddy
    network_mode: host
#    ports:
#      - 80:80
#      - 443:443
    environment:
      - CADDY_INGRESS_NETWORKS=caddy
#    networks:
#      - caddy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - caddy_data:/data
    extra_hosts:
      - host.docker.internal:host-gateway
    restart: unless-stopped

#networks:
#  caddy:
#    external: true

volumes:
  caddy_data: {}

@psyciknz
Copy link

psyciknz commented Feb 8, 2023

The container I’m trying to proxy has to be in host network (homebridge), what are the labels to get this to work, as mine in complaining they are not in the same network

@OnigamiSama
Copy link

Here is an exemple, my docker-compose for plexmediaserver in host mode networking with caddy-docker-proxy

services:
  plex:
    image: lscr.io/linuxserver/plex
    runtime: nvidia
    container_name: plex
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - NVIDIA_VISIBLE_DEVICES=all
    volumes:
      - ~/docker/containers/plex/config:/config
      - /zdata/mediaserver/library:/mnt/mediaserver/library:ro
      - ~/docker/containers/plex/transcode:/tmp
    labels:
      caddy: sub.domain.tld
      caddy.reverse_proxy: host.docker.internal:32400
    restart: unless-stopped

@psyciknz
Copy link

psyciknz commented Feb 8, 2023

hmm I can try this, but in a container I can't get host.docker.internal to resolve to anything.
If I run this:
docker run --net bridge --rm alpine nslookup gateway.docker.internal
I can see it bouncing off my external DNS servers, and I don't quite know what --dns entry I can put in to override the network ones.

@ulope
Copy link

ulope commented Mar 7, 2024

@psyciknz You need to tell the caddy container about the docker host hostname.

Taken from @OnigamiSama's example:

    extra_hosts:
      - host.docker.internal:host-gateway

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

4 participants