lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.86k stars 168 forks source link

unable to get it run #522

Open swnjfn opened 1 year ago

swnjfn commented 1 year ago

Hi, i am new to caddy and i got some issues to get the caddy run. it seems that the labels are not doing anything.

docker-compose.yml

version: '3.7'
services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    container_name: caddy
    restart: always
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - ./data/caddy:/data
#    - ./data/etc/caddy:/etc/caddy
    labels:
      caddy: "hosting.mydomain.com"
      caddy.tls: "my_email@mydomain.com"
      caddy.log.output: "stderr"
    ports:
    - 80:80
    - 443:443
    environment:
      CADDY_INGRESS_NETWORKS: caddy
    networks:
      - caddy
  portainer:
    container_name: portainer
    image: portainer/portainer-ce:latest
    ports:
      - 9443:9443
      - 9000:9000
    volumes:
      - ./data/portainer:/data
      - /var/run/docker.sock:/var/run/docker.sock
    restart: unless-stopped
    networks:
      - caddy
    labels:
      caddy: "portainer.hosting.mydomain.com"
      caddy.reverse_proxy: "{{upstreams 9000}}"
  whoami:
    image: containous/whoami
    networks:
      - caddy
    labels:
      caddy: whoami.hosting.mydomain.com
      caddy.reverse_proxy: "{{upstreams 80}}"
networks:
  caddy:
    external: true

This is what docker logs caddy returns:

{"level":"info","ts":1692088707.4034405,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1692088707.4102266,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"warn","ts":1692088707.4105172,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1692088707.4108646,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1692088707.4112356,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1692088707.411308,"msg":"serving initial configuration"}
{"level":"info","ts":1692088707.4122224,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x40004eae00"}
{"level":"info","ts":1692088707.4124367,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
{"level":"info","ts":1692088707.415829,"logger":"tls","msg":"finished cleaning storage units"}

My portainer service is only directly by 9443 available. https://portainer.hosting.mydomain.com just says not reachable by browser and on http it returns a caddy welcome page. Same with whoami.hosting.mydomain.com

i recognizes the error in the logs server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server which will happen when the default caddyfile is loaded. So i make a volume and linked it to a file, but then rises an other issue could not get certificate from issuer. Not sure whate exactly the problem is (just did a quick search), but this is not part of this post anyway. I want to use labels to configure not a caddy file by myself. So first things first, i have to get this running and then i take a look about the next error.

i am sure its just a config failure, like some typo or something but i cant figure it out. i hope someone can help me.