caddy: docker-compose 502s on some machines

1. What version of Caddy are you running (caddy -version)?

0.8.3 docker 1.11.1 compose 1.7

2. What are you trying to do?

run caddy with docker-compose

3. What is your entire Caddyfile?

http://localhost {
  log / stdout "{host} {upstream}"
  proxy / web:8080 {
    proxy_header Host {host}
    proxy_header X-Real-IP {remote}
    proxy_header X-Forwarded-Proto {scheme}
  }
}

and docker-compose.yml

version: '2'
services:
  caddy:
    image: zzrot/alpine-caddy:v0.8.3
    ports:
      - 80:80
    volumes:
      - ./Caddyfile:/etc/Caddyfile
    depends_on:
      - web
  web:
    image: ehazlett/docker-demo
    ports:
      - 8080

NOTE: I also tried @abiosoft abiosoft/caddy to make sure it’s not a problem in the docker image.

4. How did you run Caddy (give the full command and describe the execution environment)?

docker-compose up -d

5. What did you expect to see?

Everything works; I can curl localhost to get the html

6. What did you see instead (give full error messages and/or log)?

On my local boot2docker, it does work as expected On a VPS, I tried several Linux distributions, it didn’t work on any of them, not sure what’s wrong. The result was simply 502, Caddy couldn’t find the backend. Funny thing is, I tried ping and curl in Caddy container, they worked as expected.

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

Use the provided docker-compose.yml and Caddyfile and run docker-compose up. Not sure how you could reproduce 502s though, it works in boot2docker. The server I’m using is scaleway.com.

I did find one way (workaround) to make Caddy able to find the backend, which is setting a network alias for the backend service

swap the web part in the compose file above with the following:

web:
  image: ehazlett/docker-demo
  ports:
    - 8080
  networks:
    default:
      aliases:
        - app

and

-  proxy / web:8080 {
+  proxy / app:8080 {

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 32 (2 by maintainers)

Most upvoted comments

(There’s no curl in zzrot/alpine-caddy, hence I assumed you tested from the host, not the container.)

that’s based on an alpine linux image, to get curl: apk update && apk add curl, should take like 3 seconds.

I can reproduce this.

🎉 , oh wait. 😃

With max_fails 0 Caddy just hangs.

Yep, that’s right. Same behavior here.