samsal77
samsal77

Reputation: 729

docker assigning descriptive url to my docker container web applicaiton

Im new to docker so I apologize if that sounds silly.

Im running a web application in docker container. The application starts a jitty webserver . If I assign localhost or the FQDN machine name Im able to access the application from the host machine. However If I try to assign something more descriptive using my company domain as myapp.mycompany.com I get the following error in the browser: DNS_PROBE_FINISHED_NXDOMAIN ! why am I getting this error and how to make it work? I dont need to access this application outside the company's network so I really dont think I need an actual dns or do I?

I tried different things like --add-host with the container run command but it did not work. I tried editing the /etc/hosts but that did not help either.

I appreciate your help.

Thank you

Upvotes: -4

Views: 72

Answers (1)

jamedeus
jamedeus

Reputation: 321

When you access a fully qualified domain name like myapp.mycompany.com your computer will look up the domain with the DNS server. You're getting the error because there are no DNS records for this domain, so the connection cannot be resolved. Adding DNS records for the subdomain would make it public to anyone on the internet which doesn't sound like what you want.

Adding the IP and domain to /etc/hosts should work since this is checked before DNS, but it needs to be done on the client machine accessing the app (not the docker host). This is a per-client solution and needs to be repeated for every user that will access the app.

If you want the app accessible to everyone on the network your best bet is to set up local DNS and configure the router(s) to direct all DNS requests to the local DNS. Then create local DNS records pointing myapp.mycompany.com to the docker host. The request lifecycle will look like this:

  1. User types myapp.mycompany.com, their system sends it to local DNS
  2. Local DNS returns the IP of your docker host
  3. User's machine sends a request to docker host IP

Since the app runs in docker you will need a reverse proxy either way (unless you use a docker network driver that exposes the container to external requests, but that usually creates more headaches than reverse proxy). This could run in another container on the same host as your app, I've had good luck with this image. The best way to set up local DNS depends heavily on your network setup. If your router has it built in try that, otherwise look into dnsmasq, pfsense, etc.

Upvotes: 1

Related Questions