502 on Proxy to Docker Container

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 /

crm.domain.com {
        proxy /

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):

2018/12/23 20:13:22 https://crm.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?

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

curl -IL

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

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 i/o timeout
24/Dec/2018:21:08:58 +0000 [ERROR 502 /favicon.ico] dial tcp 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.

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.

1 Like

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