[SOLVED][LOCALHOST] Reverse proxy in docker-compose no such host

1. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

2. How I installed, and run Caddy:

Via docker-compose, with caddy:2.6.4-alpine image

a. System environment:

Docker Desktop v 4.8.1
MacOS v 13.2.1

b. Command:

docker compose --file docker-compose.dev.yml up caddy -d

c. Service/unit/compose file:

version: "3"
name: "tweb800"
services: 
  postgres:
    image: postgres:alpine3.17
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=symfonyweb800
      - POSTGRES_PASSWORD=postgresql__password
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./db:/data
    networks:
      - default
  
  # main symfony app
  main_app:
    build: 
      context: ./backend
      target: development
      args:
        - APP_NAME=main_app
    tty: true
    ports:
      - "${MAIN_BACKEND_PORT}:${MAIN_BACKEND_PORT}" #activities
    links : 
      - postgres
    volumes:
      - ./backend:/code
    working_dir: /code/main_app
    networks:
      - main_app
    
  # server
  caddy:
    image: caddy:2.6.4-alpine
    volumes:
      - ./backend/misc/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    ports:
        # HTTP
      - target: 80
        published: 80
        protocol: tcp
      # HTTPS
      - target: 443
        published: 443
        protocol: tcp
        # HTTP/3
      - target: 443
        published: 443
        protocol: udp
    depends_on:
      - main_app
      - activities
      - hotels
      - maps
      - restaurants
    environment:
      MAIN_BACKEND_PORT: ${MAIN_BACKEND_PORT}
      ACTIVITIES_BACKEND_PORT: ${ACTIVITIES_BACKEND_PORT}
      HOTELS_BACKEND_PORT: ${HOTELS_BACKEND_PORT}
      MAPS_BACKEND_PORT: ${MAPS_BACKEND_PORT}
      RESTAURANTS_BACKEND_PORT: ${RESTAURANTS_BACKEND_PORT}
    restart: unless-stopped


  # MICROSERVICES
  activities:
    build: 
      context: ./backend
      target: development
      args:
        - APP_NAME=activities
    tty: true
    ports:
      - "${ACTIVITIES_BACKEND_PORT}:${ACTIVITIES_BACKEND_PORT}" #activities
    links : 
      - postgres
    volumes:
      - ./backend:/code
    working_dir: /code/activities
    networks:
      - activities

  hotels:
    build: 
      context: ./backend
      target: development
      args:
        - APP_NAME=hotels
    tty: true
    ports:
      - "${HOTELS_BACKEND_PORT}:${HOTELS_BACKEND_PORT}" #hotels
    links : 
      - postgres
    volumes:
      - ./backend:/code
    working_dir: /code/hotels
    networks:
      - hotels

  maps:
    build: 
      context: ./backend
      target: development
      args:
        - APP_NAME=maps
    tty: true
    ports:
      - "${MAPS_BACKEND_PORT}:${MAPS_BACKEND_PORT}" #maps
    links : 
      - postgres
    volumes:
      - ./backend:/code
    working_dir: /code/maps
    networks:
      - maps

  restaurants:
    build: 
      context: ./backend
      target: development
      args:
        - APP_NAME=restaurants
    tty: true
    ports:
      - "${RESTAURANTS_BACKEND_PORT}:${RESTAURANTS_BACKEND_PORT}" #restaurants
    links : 
      - postgres
    volumes:
      - ./backend:/code
    working_dir: /code/restaurants
    networks:
      - restaurants




networks:
  activities: {}
  hotels: {}
  maps: {}
  restaurants: {}
  main_app: {}
volumes:
  postgres:
    driver: local
  storage:
    driver: local
  caddy_data:
  caddy_config:

d. My complete Caddy config:

{
    debug
}

epicroadtrip.local {
    encode zstd gzip
    file_server browse
}

api.epicroadtrip.local {
    encode zstd gzip
    file_server browse

    reverse_proxy main_app:8000 
}

3. The problem I’m having:

Can I access localhost:8000 on my machine ?
→ YES
Can I access epicroadtrip.local on my machine?
→ YES

I am trying to map api.epicroadtrip.local to main_app container on port 8000.

4. Error messages and/or full log output:

Result of curl -vL --insecure https://api.epicroadtrip.local

*   Trying 127.0.0.1:443...
* Connected to api.epicroadtrip.local (127.0.0.1) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: [NONE]
*  start date: Feb 21 22:00:50 2023 GMT
*  expire date: Feb 22 10:00:50 2023 GMT
*  issuer: CN=Caddy Local Authority - ECC Intermediate
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: GET]
* h2h3 [:path: /]
* h2h3 [:scheme: https]
* h2h3 [:authority: api.epicroadtrip.local]
* h2h3 [user-agent: curl/7.86.0]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x15680bc00)
> GET / HTTP/2
> Host: api.epicroadtrip.local
> user-agent: curl/7.86.0
> accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 502
< alt-svc: h3=":443"; ma=2592000
< server: Caddy
< content-length: 0
< date: Tue, 21 Feb 2023 23:06:59 GMT
<
* Connection #0 to host api.epicroadtrip.local left intact

Error message from caddy dockerized intance

{
   "level":"error",
   "ts":1677020819.036436,
   "logger":"http.log.error",
   "msg":"dial tcp: lookup main_app on 127.0.0.11:53: no such host",
   "request":{
      "remote_ip":"192.168.80.1",
      "remote_port":"55472",
      "proto":"HTTP/2.0",
      "method":"GET",
      "host":"api.epicroadtrip.local",
      "uri":"/",
      "headers":{
         "User-Agent":[
            "curl/7.86.0"
         ],
         "Accept":[
            "*/*"
         ]
      },
      "tls":{
         "resumed":false,
         "version":772,
         "cipher_suite":4867,
         "proto":"h2",
         "server_name":"api.epicroadtrip.local"
      }
   },
   "duration":0.02381975,
   "status":502,
   "err_id":"xgsndehs4",
   "err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"
}

5. What I already tried:

  • In the Caddyfile, changing the api.epicroadtrip.local to http://api.epicroadtrip.local

It seems the caddy instance is looking to map on its own “local” url and therefore can’t find the main_app one.

6. Links to relevant resources:

aaaaah F. me

I setup separate networks and then act wonder why they are separate.

My bad

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.