Home > database >  How to connect to Docker service UI via LAN on local network
How to connect to Docker service UI via LAN on local network

Time:01-22

I am new to Docker and am trying to get Nginx Proxy Manager up and running.

So far, I have a docker-compose.yml that looks like (based on a tutorial I'm following):

version: "3.9"

networks:
  default:
    driver: bridge
  npm_proxy:
    name: npm_proxy
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.89.0/24
  
x-common-keys-core: &common-keys-core
  networks:
    - npm_proxy
  security_opt:
    - no-new-privileges:true
  restart: always

services:
  npm:
    <<: *common-keys-core 
    container_name: nginx-proxy-manager
    image: 'jc21/nginx-proxy-manager:latest'
    networks:
      npm_proxy:
        ipv4_address: 192.168.89.254 
    ports:
      - '80:80'
      - '443:443'
      - '81:81'
    volumes:
      - $DOCKERDIR/appdata/npm/config:/config 
      - $DOCKERDIR/appdata/npm/letsencrypt:/etc/letsencrypt
      - $DOCKERDIR/appdata/npm/data:/data
    environment:
      DB_SQLITE_FILE: "/config/database.sqlite"
      DISABLE_IPV6: 'true'

This is works so far, and I can access the Nginx Proxy Manager on the host machine (NUC running Ubuntu connected via LAN to my router).

However, I thought that it'd be simple to access this same UI on another machine on my local network (Windows PC connected to same router via LAN).

For the life of me, I can't seem to pull up the UI on the other computer. I just get a timeout error in my browser.

I have tried:

  1. Accessing 192.168.89.254:81, which works fine on the host
  2. Adding --net=host flag
  3. Switching ports/IPs in YAML
  4. Removing custom network/bridge and just do default (i.e. localhost:81)

Does anyone know how to access the UI of a Docker service on another local PC on the same network. I don't need port-forwarding for this because it's local right?

CodePudding user response:

Seems all I had to do was expose the port in my UFW via ufw allow 81. Once exposed I can access the UI from any device in my local network.

As pointed out by @DavidMaze, it doesn't seem very useful to specify static IPs for Docker containers. It seems best practice would be to use default Docker networking, specify different ports for different containers, and just make sure these ports are accessible via UFW. Since I'm not port forwarding on my router they should only be accessible from my local network.

I'm still a little curious though as to when a bridge would be useful. It seems even with a bridge Docker connects the bridge network to the host network. So I wonder what the point is... I'll be sure read up on some documentation.

Here is my updated YAML:

version: "3.9"
  
x-common-keys-core: &common-keys-core
  security_opt:
    - no-new-privileges:true
  restart: always

services:
  npm:
    <<: *common-keys-core 
    container_name: nginx-proxy-manager
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '443:443'
      - '81:81'
    volumes:
      - $DOCKERDIR/appdata/npm/config:/config 
      - $DOCKERDIR/appdata/npm/letsencrypt:/etc/letsencrypt
      - $DOCKERDIR/appdata/npm/data:/data
    environment:
      DB_SQLITE_FILE: "/config/database.sqlite"
      DISABLE_IPV6: 'true'
  • Related