Accessing container1 from container2 by domain name

Hi I have a basic setup with two containers

  • a react app with a few server side endpoints that’s served on: domain_com
  • a graphql server that responds to both client and server requests at: graphql.domain_com

Currently the client side requests to the graphql endpoint uses the subdomain while for the server requests I have to use the container_name:port because the containers cant’ see eachother by domain (requests through url never get a response…).

This is a private app with low traffic and I would trade speed for simplicity.

So my question are:

  • how can 2 containers access each other using domains instead of docker’s network?
  • is this related to Caddy or should I look somewhere else (domain, dns…)?
  • if it’s not related to Caddy, what’s the right terms to search for?

Thank you!

Can you give concrete examples of what you’re trying to do? What’s your current Caddyfile config?

domain,com {
    reverse_proxy container1:3000

grahpql.domain,com {
    reverse_proxy container2:8080

This is the caddy file and Caddy is running in a third container. What I want is basically to be able to curl from container1 using container2’s url (grahpql.domain,com) instead of it’s container name and port (container2:8080). Currently I get no response timeout. All the requests from outside are working just fine.

I used coma above because I can’t post domains on this forum.

This is a networking issue, not at all related to Caddy. But there’s plenty of overlapping expertise.

This should be doable, but it will absolutely require more networking support than just Docker’s internal DNS/public DNS/standard routing.

First question is: inside container1, what IP address does the FQDN you’re trying to curl resolve to? Most likely this should be your external IP address?

P.S. please avoid referencing domain_com or similar; we block these for a reason, which is that this domain is actually owned by someone and we try to avoid using other people’s real domains when troubleshooting or for example purposes. is reserved specifically for this purpose and is ideal to use; as is the entire .example TLD.


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