From 3db57c62904593e8e4d8c747bb9660f3936230c6 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 13 May 2022 18:46:34 +0200 Subject: [PATCH] allow to specify the docker socket path Signed-off-by: szaimen --- Containers/mastercontainer/start.sh | 8 ++++++++ docker-compose.yml | 1 + php/containers.json | 2 +- php/src/ContainerDefinitionFetcher.php | 7 ++++++- php/src/Data/ConfigurationManager.php | 7 +++++++ readme.md | 2 +- tests/QA/060-environmental-variables.md | 1 + 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Containers/mastercontainer/start.sh b/Containers/mastercontainer/start.sh index d008ca91..0c9c8e62 100755 --- a/Containers/mastercontainer/start.sh +++ b/Containers/mastercontainer/start.sh @@ -114,6 +114,14 @@ It is set to '$APACHE_PORT'." exit 1 fi fi +if [ -n "$DOCKER_SOCKET_PATH" ]; then + if ! echo "$DOCKER_SOCKET_PATH" | grep -q "^/" || echo "$DOCKER_SOCKET_PATH" | grep -q "/$"; then + echo "You've set DOCKER_SOCKET_PATH but not to an allowed value. +The string must start with '/' and must not end with '/'. +It is set to '$DOCKER_SOCKET_PATH'." + exit 1 + fi +fi # Check DNS resolution # Prevents issues like https://github.com/nextcloud/all-in-one/discussions/565 diff --git a/docker-compose.yml b/docker-compose.yml index ee8a5bc0..46ca8cf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: # - APACHE_PORT=11000 # Is needed when running behind a reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md # - NEXTCLOUD_DATADIR=/mnt/ncdata # Allows to set the host directory for Nextcloud's datadir. See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir # - NEXTCLOUD_MOUNT=/mnt/ # Allows the Nextcloud container to access the chosen directory on the host. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host + # - DOCKER_SOCKET_PATH="/var/run/docker.sock" # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail. # # Optional: Caddy reverse proxy. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md # # You can find further examples here: https://github.com/nextcloud/all-in-one/discussions/588 diff --git a/php/containers.json b/php/containers.json index ae1ea2d9..32c5f72e 100644 --- a/php/containers.json +++ b/php/containers.json @@ -283,7 +283,7 @@ ], "volumes": [ { - "name": "/var/run/docker.sock", + "name": "%DOCKER_SOCKET_PATH%", "location": "/var/run/docker.sock", "writeable": false } diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index 92744df7..37d20e81 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -101,8 +101,13 @@ class ContainerDefinitionFetcher if ($value['name'] === '') { continue; } + } elseif ($value['name'] === '%DOCKER_SOCKET_PATH%') { + $value['name'] = $this->configurationManager->GetDockerSocketPath(); + if($value['name'] === '') { + continue; + } } - if($value['location'] === '%NEXTCLOUD_MOUNT%') { + if ($value['location'] === '%NEXTCLOUD_MOUNT%') { $value['location'] = $this->configurationManager->GetNextcloudMount(); if($value['location'] === '') { continue; diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 60fa28b3..c110f5be 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -453,6 +453,13 @@ class ConfigurationManager return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } + public function GetDockerSocketPath() : string { + $envVariableName = 'DOCKER_SOCKET_PATH'; + $configName = 'docker_socket_path'; + $defaultValue = '/var/run/docker.sock'; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); + } + /** * @throws InvalidSettingConfigurationException */ diff --git a/readme.md b/readme.md index c4c4b6b6..c9ef32d0 100644 --- a/readme.md +++ b/readme.md @@ -75,7 +75,7 @@ Only those (if you access the Mastercontainer Interface internally via port 8080 - `3478/TCP` and `3478/UDP`: will be used by the Turnserver inside the Talk container and needs to be open in your firewall/router ### How to run it on macOS? -On macOS, there is one specialty in comparison to Linux: instead of using `--volume /var/run/docker.sock:/var/run/docker.sock:ro`, you need to use `--volume /var/run/docker.sock.raw:/var/run/docker.sock:ro` to run it after you installed [Docker Desktop](https://www.docker.com/products/docker-desktop/). Apart from that it should work and behave the same like on Linux. +On macOS, there are two things different in comparison to Linux: instead of using `--volume /var/run/docker.sock:/var/run/docker.sock:ro`, you need to use `--volume /var/run/docker.sock.raw:/var/run/docker.sock:ro` to run it after you installed [Docker Desktop](https://www.docker.com/products/docker-desktop/). You also need to add `-e DOCKER_SOCKET_PATH="/var/run/docker.sock.raw"`to the startup command. Apart from that it should work and behave the same like on Linux. ### How to run it on Windows? On Windows, the following command should work after you installed [Docker Desktop](https://www.docker.com/products/docker-desktop/): diff --git a/tests/QA/060-environmental-variables.md b/tests/QA/060-environmental-variables.md index 66b91471..d6e3d6bf 100644 --- a/tests/QA/060-environmental-variables.md +++ b/tests/QA/060-environmental-variables.md @@ -4,5 +4,6 @@ - [ ] 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 `-e NEXTCLOUD_DATADIR="/mnt/testdata"` it should map that location from `/mnt/testdata` to `/mnt/ncdata` inside the Nextcloud container. Not having adjusted the permissions correctly before starting the Nextcloud container the first time will not allow the Nextcloud container to start correctly. See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir for allowed values. - [ ] When starting the mastercontainer with `-e NEXTCLOUD_MOUNT="/mnt/"` it should map `/mnt/` to `/mnt/` inside the Nextcloud container. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host for allowed values. +- [ ] When starting the mastercontainer with `-e DOCKER_SOCKET_PATH="/var/run/docker.sock.raw"` it should map `/var/run/docker.sock.raw` to `/var/run/docker.sock` inside the watchtower container which allow to update the mastercontainer on macos and with docker rootless. You can now continue with [070-timezone-change.md](./070-timezone-change.md)