Expose dockerized instance to LAN

Currently 80 port is available for localhost only. Ngingx’s container doesn’t allow using EXPOSE neither in .yml nor inside the container. Ufw doesn’t work either. How can I expose port 80 to LAN?

Search Issues · frappe/frappe_docker · GitHub

Not simple.
You’ll need to setup dns server.

Leaving a solution for a development instance. It exposes the instance to the Internet as well (if you open ports).

Make your DNS service listening to Docker

Open or create /etc/NetworkManager/dnsmasq.d/docker-bridge.conf:

Add the following line (your docker0 network):

listen-address=172.17.0.1

Change DNS settings for Docker daemon

Create /etc/docker/daemon.json:

Add your network’s DNS server and fallback options (e.g. Google DNS):

{
    "dns": [ "172.17.0.1", "8.8.8.8", "8.8.8.4" ]
}

Then restart the docker service:

sudo service docker restart

I’m looking to do this as well. Did you set up Docker using based on env-local? What do you use as site name and how do you access it from the LAN, with IP address or site-name.local/sinte-name.lan domains? I don’t really care, but out of curiosity, why does it need any DNS defined?

frappe_docker is based on DNS based multitenancy

That means the site is resolved from the Host header or X-Frappe-Site-Name header.
Check here frappe/app.py at 66083cece14c532eca047966715fdb5ebff4bd22 · frappe/frappe · GitHub

Reverse proxy in front of erpnext-nginx is needed to override Host or set appropriate header. This may work when only one site is needed on lan.

In case *.lan or *.local sites are needed on LAN then use a DNS server. Set that as primary dns server on machines on LAN.

Are you talking about doing this? I did that but it caused 404 on site-name.localhost, same with .lan, .local or just .localhost.

No.

Use DNS to resolve custom site names from LAN. Production image: Installed and up but not reachable · Issue #172 · frappe/frappe_docker · GitHub

It won’t work.

Either use it from local machine itself for testing.
Or for LAN you need DNS Server.

Yes, I’m testing with browser on the server itself; on Ubuntu 20.04 Desktop I installed Docker from the Docker repo.

After docker-compose --project-name erp up -d, going to http://hostname in Firefox on the server itself, I get Bad Gateway.

I edited /etc/hosts line from 127.0.1.1 to 127.0.0.1 and now the message changed to 404 page not found.

ONLY hostname.localhost will work from local machine

Then on my DNS am I to add hostname.localhost to translate to 192.168.0.5? I don’t think you can .localhost to DNS.

which /etc/hosts? the one inside container or the one on docker host machine?

change the /etc/hosts of docker host machine and try

With DNS anything (any site name) will work.

Do you have DNS setup? try it.

For local machine edit the /etc/hosts of host machine and try

I did not change anything in the container. Host machines /etc/hosts changed hostname 127.0.1.1 to hostname 127.0.0.1, and got 404 page not found error on browser running on host.

If I understand correctly, you’re telling me:

  • SITE-NAME can be anything but always ending with .localhost, in this example hostname.localhost.
  • Local DNS should be hostname (or any other SITE-NAME I used) pointing to my Docker host IP address.

Did I get it right so far?

  • SITE_NAME is used by site-creator container to create that site. Site created should resolve as app.py needs that. You can name it anything and it will create the directory under frappe-bench/sites. As long as the request with the specified headers reach the erpnext-nginx it will resolve the site and serve it.
  • SITES is list of domain names for setting up letsencrypt.

If you’re on VPS / Cloud server .localhost won’t work.