I have an issue when trying to access the Nextcloud AIO installation from a Nginx reverse proxy running on the same machine.
I follow the docs at:
Section 1.3: 1. On the same server in a Docker container
I dont want to put the Nginx container on the network:host so I go for the: host.docker.internal:host-gateway.
From the Nginx container I run this to test connectivity:
# curl -v http://host.docker.internal:11000
* Trying 172.17.0.1:11000...
* connect to 172.17.0.1 port 11000 failed: Connection timed out
nginx container have IP: 172.23.0.3
nextcloud-aio-nextcloud have IP: 172.20.0.11
They are on different networks. What do I miss in the documentation?
The Reverse Proxy documentation seems to be valid when Nginx and Nextcloud are in the same Docker network. In my case I have Nginx and Nextcloud in different docker-compose project on the same Docker host.
As I understand it:
I cannot directly reference a default network created by one Docker Compose file from another Docker Compose file.
Maybe I shall manually the networks and assign it to the containers?
When I add the network nextcloud-aio to the container webfront_nginx I’m able to reach nextcloud-aio-apache from webfront_nginx:
eg. curl http://nextcloud-aio-apache:11000 -v
Maybe that is what I have to do, but I don’t know how to add it to my nextcloud/docker-compose.yaml-file?
It’s ugly and I’m certain there MUST be a better method to allow using multiple docker-compose files but this works now so I haven’t researched it extensively.
*EDIT: the reason I’m manualy creating the network and using external: true in both nginx and nextcloud is to avoid issues where the network may not exist yet.
Note: when referencing the docker container name in your proxy pass you can set the docker resolver and use variables. This makes sure nginx will resolve the name on access rather on the proxy start-up, otherwise nginx will complain the domain can’t be resolved if the nextcloud container is down and fail to start.
resolver 127.0.0.11 valid=10s; #Docker resolver with short valid time
set $upstream_app nextcloud_notify; #Docker container name
set $upstream_port 7867;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
There are several possible approaches here. One option could be to configure the Nginx container to use the host network by setting network: host .
This way, you wouldn’t need to manually add all Docker networks from various containers (such as Nextcloud and other web applications you want to access through the Nginx proxy) to the Nginx container.