mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 06:26:57 +00:00
Merge pull request #5484 from apparle/apache_additional_network
Specifying additional docker network for Apache container
This commit is contained in:
commit
cd3a33a800
6 changed files with 60 additions and 25 deletions
|
|
@ -193,6 +193,14 @@ It is set to '$APACHE_IP_BINDING'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$APACHE_ADDITIONAL_NETWORK" ]; then
|
||||||
|
if ! echo "$APACHE_ADDITIONAL_NETWORK" | grep -q "^[a-zA-Z0-9_-]\+$"; then
|
||||||
|
print_red "You've set APACHE_ADDITIONAL_NETWORK but not to an allowed value.
|
||||||
|
It needs to be a string with letters, numbers, hyphens and underscores.
|
||||||
|
It is set to '$APACHE_ADDITIONAL_NETWORK'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [ -n "$TALK_PORT" ]; then
|
if [ -n "$TALK_PORT" ]; then
|
||||||
if ! check_if_number "$TALK_PORT"; then
|
if ! check_if_number "$TALK_PORT"; then
|
||||||
print_red "You provided an Talk port but did not only use numbers.
|
print_red "You provided an Talk port but did not only use numbers.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ services:
|
||||||
# AIO_COMMUNITY_CONTAINERS: # With this variable, you can add community containers very easily. See https://github.com/nextcloud/all-in-one/tree/main/community-containers#community-containers
|
# AIO_COMMUNITY_CONTAINERS: # With this variable, you can add community containers very easily. See https://github.com/nextcloud/all-in-one/tree/main/community-containers#community-containers
|
||||||
# APACHE_PORT: 11000 # Is needed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
|
# APACHE_PORT: 11000 # Is needed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
|
||||||
# APACHE_IP_BINDING: 127.0.0.1 # Should be set when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
|
# APACHE_IP_BINDING: 127.0.0.1 # Should be set when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
|
||||||
|
# APACHE_ADDITIONAL_NETWORK: frontend_net # (Optional) Connect the apache container to an additional docker network. Needed when behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) running in a different docker network on same server. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
|
||||||
# BORG_RETENTION_POLICY: --keep-within=7d --keep-weekly=4 --keep-monthly=6 # Allows to adjust borgs retention policy. See https://github.com/nextcloud/all-in-one#how-to-adjust-borgs-retention-policy
|
# BORG_RETENTION_POLICY: --keep-within=7d --keep-weekly=4 --keep-monthly=6 # Allows to adjust borgs retention policy. See https://github.com/nextcloud/all-in-one#how-to-adjust-borgs-retention-policy
|
||||||
# COLLABORA_SECCOMP_DISABLED: false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
|
# COLLABORA_SECCOMP_DISABLED: false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
|
||||||
# NEXTCLOUD_DATADIR: /mnt/ncdata # Allows to set the host directory for Nextcloud's datadir. ⚠️⚠️⚠️ Warning: do not set or adjust this value after the initial Nextcloud installation is done! See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
|
# NEXTCLOUD_DATADIR: /mnt/ncdata # Allows to set the host directory for Nextcloud's datadir. ⚠️⚠️⚠️ Warning: do not set or adjust this value after the initial Nextcloud installation is done! See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
|
||||||
|
|
|
||||||
|
|
@ -888,6 +888,13 @@ class ConfigurationManager
|
||||||
$this->WriteConfig($config);
|
$this->WriteConfig($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetApacheAdditionalNetwork() : string {
|
||||||
|
$envVariableName = 'APACHE_ADDITIONAL_NETWORK';
|
||||||
|
$configName = 'apache_additional_network';
|
||||||
|
$defaultValue = '';
|
||||||
|
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
public function GetApacheIPBinding() : string {
|
public function GetApacheIPBinding() : string {
|
||||||
$envVariableName = 'APACHE_IP_BINDING';
|
$envVariableName = 'APACHE_IP_BINDING';
|
||||||
$configName = 'apache_ip_binding';
|
$configName = 'apache_ip_binding';
|
||||||
|
|
|
||||||
|
|
@ -841,12 +841,13 @@ readonly class DockerActionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ConnectContainerIdToNetwork(string $id, string $internalPort, string $network = 'nextcloud-aio') : void
|
private function ConnectContainerIdToNetwork(string $id, string $internalPort, string $network = 'nextcloud-aio', bool $createNetwork = true, string $alias = '') : void
|
||||||
{
|
{
|
||||||
if ($internalPort === 'host') {
|
if ($internalPort === 'host') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($createNetwork) {
|
||||||
$url = $this->BuildApiUrl('networks/create');
|
$url = $this->BuildApiUrl('networks/create');
|
||||||
try {
|
try {
|
||||||
$this->guzzleClient->request(
|
$this->guzzleClient->request(
|
||||||
|
|
@ -867,18 +868,22 @@ readonly class DockerActionManager {
|
||||||
throw new \Exception("Could not create the nextcloud-aio network: " . $e->getMessage());
|
throw new \Exception("Could not create the nextcloud-aio network: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$url = $this->BuildApiUrl(
|
$url = $this->BuildApiUrl(
|
||||||
sprintf('networks/%s/connect', $network)
|
sprintf('networks/%s/connect', $network)
|
||||||
);
|
);
|
||||||
|
$jsonPayload = [ 'Container' => $id ];
|
||||||
|
if ($alias !== '' ) {
|
||||||
|
$jsonPayload['EndpointConfig'] = ['Aliases' => [ $alias ]];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->guzzleClient->request(
|
$this->guzzleClient->request(
|
||||||
'POST',
|
'POST',
|
||||||
$url,
|
$url,
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => $jsonPayload
|
||||||
'container' => $id,
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
|
|
@ -898,7 +903,19 @@ readonly class DockerActionManager {
|
||||||
|
|
||||||
public function ConnectContainerToNetwork(Container $container) : void
|
public function ConnectContainerToNetwork(Container $container) : void
|
||||||
{
|
{
|
||||||
$this->ConnectContainerIdToNetwork($container->GetIdentifier(), $container->GetInternalPort());
|
// Add a secondary alias for domaincheck container, to keep it as similar to actual apache controller as possible.
|
||||||
|
// If a reverse-proxy is relying on container name as hostname this allows it to operate as usual and still validate the domain
|
||||||
|
// The domaincheck container and apache container are never supposed to be active at the same time because they use the same APACHE_PORT anyway, so this doesn't add any new constraints.
|
||||||
|
$alias = ($container->GetIdentifier() === 'nextcloud-aio-domaincheck') ? 'nextcloud-aio-apache' : '';
|
||||||
|
|
||||||
|
$this->ConnectContainerIdToNetwork($container->GetIdentifier(), $container->GetInternalPort(), alias: $alias);
|
||||||
|
|
||||||
|
if ($container->GetIdentifier() === 'nextcloud-aio-apache' || $container->GetIdentifier() === 'nextcloud-aio-domaincheck') {
|
||||||
|
$apacheAdditionalNetwork = $this->configurationManager->GetApacheAdditionalNetwork();
|
||||||
|
if ($apacheAdditionalNetwork !== '') {
|
||||||
|
$this->ConnectContainerIdToNetwork($container->GetIdentifier(), $container->GetInternalPort(), $apacheAdditionalNetwork, false, $alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StopContainer(Container $container) : void {
|
public function StopContainer(Container $container) : void {
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ All examples below will use port `11000` as `APACHE_PORT`. This port will be exp
|
||||||
|
|
||||||
<summary>On the same server in a Docker container</summary>
|
<summary>On the same server in a Docker container</summary>
|
||||||
|
|
||||||
For this setup, you can use as target `host.docker.internal:$APACHE_PORT` instead of `localhost:$APACHE_PORT`. **⚠️ Important:** In order to make this work on Docker for Linux, you need to add `--add-host=host.docker.internal:host-gateway` to the docker run command of your reverse proxy container or `extra_hosts: ["host.docker.internal:host-gateway"]` in docker compose (it works on Docker Desktop by default).
|
The reverse-proxy container needs to be connected to the nextcloud containers. This can be achieved one of these 3 ways:
|
||||||
|
1. Utilize host networking instead of docker bridge networking: Specify `--network host` option (or `network_mode: host` for docker-compose) as setting for the reverse proxy container to connect it to the host network. If you are using a firewall on the server, you need to open ports 80 and 443 for the reverse proxy manually. With this setup, the default sample configurations with reverse-proxy pointing to `localhost:$APACHE_PORT` should work directly.
|
||||||
Another option (actually the recommended way) in this case is to use `--network host` option (or `network_mode: host` for docker-compose) as setting for the reverse proxy container to connect it to the host network. If you are using a firewall on the server, you need to open ports 80 and 443 for the reverse proxy manually. By doing so, the default sample configurations that point at `localhost:$APACHE_PORT` should work without having to modify them.
|
1. Connect nextcloud's external-facing containers to the reverse-proxy's docker network by specifying env variable APACHE_ADDITIONAL_NETWORK. With this setup, the reverse proxy can utilize Docker bridge network's DNS name resolution to access nextcloud at `http://nextcloud-aio-apache:$APACHE_PORT`. ⚠️⚠️⚠️ Note, the specified network must already exist before Nextcloud AIO is started. Otherwise it will fail to start the container because the network is not existing.
|
||||||
|
1. Connect the reverse-proxy container to the `nextcloud-aio` network by specifying it as a secondary (external) network for the reverse proxy container. With this setup also, the reverse proxy can utilize Docker bridge network's DNS name resolution to access nextcloud at `http://nextcloud-aio-apache:$APACHE_PORT` .
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- [ ] When starting the mastercontainer with `--env APACHE_PORT=11000` on a clean instance, the domaincheck container should be started with that same port published. That makes sure that also the Apache container will use that port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. However `@INTERNAL` is also an allowed value which skips publishing the port on the host for internal usage inside a bridged network for example.
|
- [ ] When starting the mastercontainer with `--env APACHE_PORT=11000` on a clean instance, the domaincheck container should be started with that same port published. That makes sure that also the Apache container will use that port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. However `@INTERNAL` is also an allowed value which skips publishing the port on the host for internal usage inside a bridged network for example.
|
||||||
- [ ] When starting the mastercontainer with `--env APACHE_IP_BINDING=127.0.0.1` on a clean instance, the domaincheck container's apache port should only listen on localhost on the host. Using a value here that is not a number or dot will not allow the mastercontainer to start correctly.
|
- [ ] When starting the mastercontainer with `--env APACHE_IP_BINDING=127.0.0.1` on a clean instance, the domaincheck container's apache port should only listen on localhost on the host. Using a value here that is not a number or dot will not allow the mastercontainer to start correctly.
|
||||||
|
- [ ] When starting the mastercontainer with `--env APACHE_ADDITIONAL_NETWORK=frontend_net` on a clean instance, the domaincheck and subsequently the apache containers should be connected to the specified `frontend_net` docker network, in addition to the default `nextcloud-aio` network. Specifying the network that doesn't already exist will not allow the mastercontainer to start correctly.
|
||||||
- [ ] When starting the mastercontainer with `--env TALK_PORT=3479` on a clean instance, the talk container should use this port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. Also it should stop if apache_port and talk_port are set to the same value.
|
- [ ] When starting the mastercontainer with `--env TALK_PORT=3479` on a clean instance, the talk container should use this port later on. Using a value here that is not a port will not allow the mastercontainer to start correctly. Also it should stop if apache_port and talk_port are set to the same value.
|
||||||
- [ ] Make also sure that reverse proxies work by following https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#reverse-proxy-documentation and following [001-initial-setup.md](./001-initial-setup.md) and [002-new-instance.md](./002-new-instance.md)
|
- [ ] Make also sure that reverse proxies work by following https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#reverse-proxy-documentation and following [001-initial-setup.md](./001-initial-setup.md) and [002-new-instance.md](./002-new-instance.md)
|
||||||
- [ ] When starting the mastercontainer with `--env SKIP_DOMAIN_VALIDATION=true` on a clean instance, it should skip the domain verification. So it should accept any domain that you type in then.
|
- [ ] When starting the mastercontainer with `--env SKIP_DOMAIN_VALIDATION=true` on a clean instance, it should skip the domain verification. So it should accept any domain that you type in then.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue