502 on Proxy to Docker Container


(Rudhra Raveendran) #1

I added a new docker container for the Monica CRM following this guide. The docker container itself is working fine, it maps the host port 3000 to container port 80. If I try accessing the service through my server’s ip like so: http:ipaddress:3000 I’m able to use the service.

However, I wanted to assign a domain name to it. I’ve done this in the past by having sub.domain.com point to my server ip address, and from there using Caddy to proxy the request. Here’s what my Caddyfile looks like:

blog.domain.com {
        proxy / 172.17.0.2:2368
}

crm.domain.com {
        proxy / 172.18.0.3:80
}

The blog proxy works fine, but the crm one does not (throws 502). The logs show nothing of importance, just lines like this (from me testing the domains):

https://crm.rooday.com
2018/12/23 20:13:22 https://crm.rooday.com
http://blog.rooday.com

The IP addresses that the proxies point to in the Caddyfile were found through Docker inspect, and again it works for the blog subdomain, so I’m not sure what’s going on with the new one. Any thoughts?


(Matthew Fay) #2

Try running a command from the Caddy host to send a request to your CRM and see what you get in response:

curl -IL 172.18.0.3:80

You can also try adding errors /path/to/error.log to the CRM site in your Caddyfile and see what turns up.


(Rudhra Raveendran) #3

When I curl that IP it works fine but the proxy is still failing. I added an errors file and I see this in the log:

24/Dec/2018:21:08:26 +0000 [ERROR 502 /] dial tcp 172.18.0.3:80: i/o timeout
24/Dec/2018:21:08:58 +0000 [ERROR 502 /favicon.ico] dial tcp 172.18.0.3:80: i/o timeout

What could be causing the timeout? Monica, my blog, and caddy all run in docker containers, but caddy seems to have no trouble proxying to the blog container, and I’m able to curl the Monica container just fine.


(Rudhra Raveendran) #4

Nevermind, solved it! The way the monica docker containers were being built was putting them on a separate network than the rest of my containers, so they weren’t able to communicate. I fixed this by adding the network_mode directive for the services in the monica docker-compose.yml so that they’d be attached to my existing network.