1

I'm deploying nextcloud via docker, however the way the configuration is set up, it creates a subnetwork at 10.10.10.0/24 on the system it's running on instead of running it on 127.0.0.1. Then the only way to access it is by navigating to 10.10.0.5 on the host machine.

However, I want to be able to access this image from every machine on my local network.

I already have a few things running, so I need to map the port as well.

Is there an intuitive way to map the network such that navigating to 127.0.0.1:2287 maps it to 10.10.0.5? I can't seem to find anything indicating how to do this.

I would think this would have to be a bidirectional mapping since it needs to send data back since it's nextcloud, but I'm unsure about this.

I did try setting up the docker container to report to 127.0.0.1 but it didn't work out. It would only report on 172.19.0.5

If you wanted to see my docker setup, it's as follows:

  1. Create the subnetwork for docker: docker network create --driver=bridge --subnet=10.10.10.0/24 --gateway=10.10.10.1 dockernet

  2. Run docker-compose

version: '3' 

services:
  nextclouddb:
    image: mariadb
    container_name: nextcloud-mariadb
    volumes:
      - /home/username/data/mysql:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    networks:
      default:
        ipv4_address: 10.10.10.4
    environment:
      - MYSQL_ROOT_PASSWORD=STONGPASSWORD
      - MYSQL_PASSWORD=ANOTHERSTONGPASSWORD
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    restart: unless-stopped
  
  nextcloudapp:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
      default:
        ipv4_address: 10.10.10.5
    volumes:
      - /home/username/data/html:/var/www/html
      - /home/username/data/config:/var/www/html/config
      - /home/username/data/apps:/var/www/html/custom_apps
      - /home/username/data/data:/var/www/html/data
      - /home/username/data/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped

networks:
  default:
    external:
      name: dockernet
2
  • Are you trying to map local port to a specific internal port - perhaps try the Connect a container to a user-defined bridge
    – Mr R
    Commented Mar 21, 2021 at 19:41
  • You should re read docker documentation, docker networks are aimed at allowing inter container communications, docker is about isolation of processes, including what port they're listining on, if a port is to be exposed to the external world, well it has to be exposed on the docker host.
    – Tensibai
    Commented Mar 23, 2021 at 14:16

1 Answer 1

1

Do you have network constraints to create a new subnet or what is the reason? if it's not useful at all, you can just map the port and open the firewall of your PC so that the other machines can see the application.

version: '3' 
services:
  nextclouddb:
    image: mariadb
    container_name: nextcloud-mariadb
    volumes:
      - /home/username/data/mysql:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=STONGPASSWORD
      - MYSQL_PASSWORD=ANOTHERSTONGPASSWORD
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    restart: unless-stopped
  
  nextcloudapp:
    image: nextcloud:latest
    container_name: nextcloud-app
    volumes:
      - /home/username/data/html:/var/www/html
      - /home/username/data/config:/var/www/html/config
      - /home/username/data/apps:/var/www/html/custom_apps
      - /home/username/data/data:/var/www/html/data
      - /home/username/data/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    ports:
      - 2287:80  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.