From 94560a0b39fc3b4955611d80fc1b021f822e79cb Mon Sep 17 00:00:00 2001 From: Pathros Date: Wed, 14 Jul 2021 16:32:51 -0500 Subject: [PATCH 1/3] I added support for Docker Rootless. This has been possible by adding the possibility to bind the docker.sock to the user's current $XDG_RUNTIME_DIR, which is found in the user's .bashrc file, that he added after installing docker rootless, by following the instructions from the official documentation (https://docs.docker.com/engine/security/rootless/) to run the Docker Daemon as a non-root user. To achieve this, I made the following changes: 1) I added the DOCKER_HOST_ROOTLESS_PATH= variable inside the .env.sample file. 2) I updated in the two required lines of the docker-compose.yml file, the following: ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock} , instead of /var/run/docker.sock:/tmp/docker.sock:ro, so that this fixes the "Error: you need to share your Docker host socket with a volume at /var/run/docker.sock. Typically you should run your container with: '-v /var/run/docker.sock:/var/run/docker.sock:ro'" error when using docker rootless. 3) I attempted to update the MD5 of both the .env.sample & docker-compose.yml file [PLEASE CHECK] 4) I updated the usage text in the usage-fresh-start.sh file, so that the user can notice this optional flag: either "-dr" or "--docker-rootless" 5) I updated the update-env-new-site-variables.sh to update the .env DOCKER_HOST_ROOTLESS_PATH to set the user's current $XDG_RUNTIME_DIR, in case the "-dr" flag has been specified. Otherwise, this is left blank and no further action is done. 6) I updated the fresh-start.sh file to take into account the "-dr" flag. Shouldn't the "-dr" flag be specified, the programme should continue normally. --- .env.sample | 12 +++++++++++ bin/.env | 4 ++-- bin/fresh-start.sh | 20 +++++++++++++++++++ .../update-env-new-site-variables.sh | 3 +++ bin/localscript/usage-fresh-start.sh | 5 +++++ docker-compose.yml | 4 ++-- 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.env.sample b/.env.sample index f9331bc..9ff6f12 100644 --- a/.env.sample +++ b/.env.sample @@ -121,3 +121,15 @@ DEFAULT_EMAIL=mail@yourdomain.tld # https://github.com/nginx-proxy/nginx-proxy#default-host # DEFAULT_HOST= + +#----------------------------------------------------------------------- +# +# Docker Rootless +# +# In case you want to use this proxy on Docker Rootless (DR) and you also have followed +# the DR installation from the official documentation (https://docs.docker.com/engine/security/rootless/) +# Set the following value of the DOCKER_HOST variable that you got in the final info messages after executing +# the "$ dockerd-rootless-setuptool.sh install" command. +# For example DOCKER_HOST_PATH=$XDG_RUNTIME_DIR/docker.sock +# If you are not using Docker Rootless, leave this variable blank +DOCKER_HOST_ROOTLESS_PATH= \ No newline at end of file diff --git a/bin/.env b/bin/.env index 99e47f3..fa1ffab 100644 --- a/bin/.env +++ b/bin/.env @@ -56,5 +56,5 @@ REPLACE_LETSENCRYPT_SERVICE_NAME="nginx-proxy-automation-letsencrypt" # # md5 checksum for .env and docker-compose.yml files # -MD5_SUM_DOCKER_COMPOSE=acb712ecf4c2edd04583032b1cd4da07 -MD5_SUM_ENV_SAMPLE=b299b584d68c1a6f7ac1b1a753a7517d +MD5_SUM_DOCKER_COMPOSE=7c9ed211bde6eb11d6c71d4f9705f1ad +MD5_SUM_ENV_SAMPLE=5b0f91894cf1417f5f445369c90bc10a diff --git a/bin/fresh-start.sh b/bin/fresh-start.sh index 50ab85b..d62c976 100755 --- a/bin/fresh-start.sh +++ b/bin/fresh-start.sh @@ -429,6 +429,16 @@ while [[ $# -gt 0 ]]; do shift 1 ;; + # Docker rootless support + -dr) + USE_DOCKER_ROOTLESS=true + shift 1 + ;; + --docker-rootless) + USE_DOCKER_ROOTLESS=true + shift 1 + ;; + # IPv4 options --ipv4-subnet=*) ARG_IPv4_SUBNET="${1#*=}" @@ -1121,6 +1131,16 @@ DOCKER_HTTPS=${ARG_DOCKER_HTTPS:-"443"} #----------------------------------------------------------------------- SSL_POLICY=${ARG_SSL_POLICY:-"Mozilla-Intermediate"} +#----------------------------------------------------------------------- +# Docker rootless support. Add the current user's docker.sock path (default: blank) +# Please read the official documentation of installing Docker Rootless: +# https://docs.docker.com/engine/security/rootless/ +#----------------------------------------------------------------------- +if [[ "$USE_DOCKER_ROOTLESS" == true ]]; then + # Get the current user's $XDG_RUNTIME_DIR and concat with the '/docker.sock' + DOCKER_HOST_ROOTLESS_PATH=`echo ${XDG_RUNTIME_DIR}/docker.sock` +fi + #----------------------------------------------------------------------- # Start actions! #----------------------------------------------------------------------- diff --git a/bin/localscript/update-env-new-site-variables.sh b/bin/localscript/update-env-new-site-variables.sh index 3a5d9d1..42b8c1a 100755 --- a/bin/localscript/update-env-new-site-variables.sh +++ b/bin/localscript/update-env-new-site-variables.sh @@ -78,5 +78,8 @@ local_update_env_new_site_variables() # Default host [[ ! $ARG_DEFAULT_HOST == "" ]] && run_function env_update_variable $LOCAL_FILE_PATH "DEFAULT_HOST" "${ARG_DEFAULT_HOST}" + # Docker rootless support + run_function env_update_variable $LOCAL_FILE_PATH "DOCKER_HOST_ROOTLESS_PATH" "$DOCKER_HOST_ROOTLESS_PATH" + return 0 } diff --git a/bin/localscript/usage-fresh-start.sh b/bin/localscript/usage-fresh-start.sh index 2493ec5..9496cb9 100755 --- a/bin/localscript/usage-fresh-start.sh +++ b/bin/localscript/usage-fresh-start.sh @@ -64,6 +64,7 @@ Usage: [--use-nginx-conf-files] [--update-nginx-template] [--yes] [--debug] + [--docker-rootless] Required -e | --default-email Default email address require to issue ssl @@ -131,6 +132,10 @@ Usage: --yes Set "yes" to all, use it with caution --debug Show script debug options --silent Hide all script message + -dr | --docker-rootless Add Docker rootless support by adding the + the current user's $XDG_RUNTIME_DIR and + concat with the '/docker.sock' in the + DOCKER_HOST_ROOTLESS_PATH .env file. -h | --help Display this help ${reset} diff --git a/docker-compose.yml b/docker-compose.yml index f8c428e..747c7b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: - ${NGINX_FILES_PATH:-./data}/html:/usr/share/nginx/html - ${NGINX_FILES_PATH:-./data}/certs:/etc/nginx/certs:ro - ${NGINX_FILES_PATH:-./data}/htpasswd:/etc/nginx/htpasswd:ro - - /var/run/docker.sock:/tmp/docker.sock:ro + - ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:/tmp/docker.sock:ro - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro logging: driver: ${NGINX_GEN_LOG_DRIVER:-json-file} @@ -57,7 +57,7 @@ services: - ${NGINX_FILES_PATH:-./data}/html:/usr/share/nginx/html - ${NGINX_FILES_PATH:-./data}/certs:/etc/nginx/certs:rw - ${NGINX_FILES_PATH:-./data}/acme.sh:/etc/acme.sh - - /var/run/docker.sock:/var/run/docker.sock:ro + - ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:ro environment: NGINX_DOCKER_GEN_CONTAINER: ${DOCKER_GEN_SEVICE_NAME:-nginx-proxy-automation-gen} NGINX_PROXY_CONTAINER: ${NGINX_WEB_SEVICE_NAME:-nginx-proxy-automation-web} From 1c68ed2342b4e18f4ea4b90cf928efa33c263f44 Mon Sep 17 00:00:00 2001 From: Pathros Date: Wed, 14 Jul 2021 17:26:52 -0500 Subject: [PATCH 2/3] Fixed an important typo in docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 747c7b2..dba208f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -57,7 +57,7 @@ services: - ${NGINX_FILES_PATH:-./data}/html:/usr/share/nginx/html - ${NGINX_FILES_PATH:-./data}/certs:/etc/nginx/certs:rw - ${NGINX_FILES_PATH:-./data}/acme.sh:/etc/acme.sh - - ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:ro + - ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:/var/run/docker.sock:ro environment: NGINX_DOCKER_GEN_CONTAINER: ${DOCKER_GEN_SEVICE_NAME:-nginx-proxy-automation-gen} NGINX_PROXY_CONTAINER: ${NGINX_WEB_SEVICE_NAME:-nginx-proxy-automation-web} From 356d18634013131906cd77ecea155062dbf5edb4 Mon Sep 17 00:00:00 2001 From: Pathros Date: Wed, 14 Jul 2021 17:30:34 -0500 Subject: [PATCH 3/3] Updated the docker-compose.yml file md5 sum --- bin/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/.env b/bin/.env index fa1ffab..d1e8070 100644 --- a/bin/.env +++ b/bin/.env @@ -56,5 +56,5 @@ REPLACE_LETSENCRYPT_SERVICE_NAME="nginx-proxy-automation-letsencrypt" # # md5 checksum for .env and docker-compose.yml files # -MD5_SUM_DOCKER_COMPOSE=7c9ed211bde6eb11d6c71d4f9705f1ad +MD5_SUM_DOCKER_COMPOSE=f06283de0336cd0f9f7749483586ab45 MD5_SUM_ENV_SAMPLE=5b0f91894cf1417f5f445369c90bc10a