how to assign domain to website on docker?

0

Issue

I want to run several .NET Core sites on a Linux server with Docker
I also want to assign a domain to each of the sites

I have two questions

  1. Do I have to assign the domain to the site with the help of a web server like nginx?
  2. Do I have to create a yml file service for each site and each with a separate nginx, or run a nginx for all sites?

Solution

Assuming that you mean a public (Internet) domain name, there are a few steps.

Domains in this context comprise a unique identifying name e.g. example.com and a set of resource records that explain how the domain is used.

In your case, you probably need to use A(ddress) record(s) that map hosts (!) on your domain to the IP(v4) address of the machines (!) running your containers.

NOTE Domain records allow other machines to lookup your machines by names (e.g. www.example.com) rather than by e.g. IP(v4) address. Your host machines do not contain any part of the domain record.

A domain name A record (e.g. www.example.com) combines a host name (www) with a domain name (example.com) and resolves (points) to the IP(v4) address of (host) machine(s).

The (host) machines may run e.g. multiple containers (services) each running on a specific port. To address (using a URL) a specific service, you combine a protocol, a host name, a domain name and a port (e.g. https://www.example.com:8443).

NGINX permits you to proxy multiple services behind a single service endpoint. NGINX is also a web server but I’m treating it solely as a (reverse) proxy in what follows.

Assuming that your NGINX service were running on port 8443 on the host www on the machine pointed to by the A record in your domain, you could program NGINX to proxy content such that, the URL (address) https://www.example.com:8443/service-1 and https://www.example.com:8443/service-2 are actually sent to other containers (which may or may not be running on www and are probably bound to a different ports).

In summary you don’t assign domain names|records using a web server but using a domain registrar or service. You can create domain records that point to specific machines and, when combined with protocols and ports, permit you to access specific services running on those machines. Additionally, you can configure proxies (like NGINX) that permit you to combine multiple services into a single, coherent service. Importantly configure domains and configuring proxies solve distinct problems.

Answered By – DazWilkin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More