Skip to content

Commit 2875ea3

Browse files
pathrosevertramos
andauthored
Docker rootless support (#311)
* 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. * Fixed an important typo in docker-compose.yml * Updated the docker-compose.yml file md5 sum Co-authored-by: Evert Ramos <[email protected]>
1 parent 8929d96 commit 2875ea3

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

.env.sample

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,15 @@ [email protected]
132132
# https://github.com/nginx-proxy/nginx-proxy#default-host
133133
#
134134
DEFAULT_HOST=
135+
136+
#-----------------------------------------------------------------------
137+
#
138+
# Docker Rootless
139+
#
140+
# In case you want to use this proxy on Docker Rootless (DR) and you also have followed
141+
# the DR installation from the official documentation (https://docs.docker.com/engine/security/rootless/)
142+
# Set the following value of the DOCKER_HOST variable that you got in the final info messages after executing
143+
# the "$ dockerd-rootless-setuptool.sh install" command.
144+
# For example DOCKER_HOST_PATH=$XDG_RUNTIME_DIR/docker.sock
145+
# If you are not using Docker Rootless, leave this variable blank
146+
DOCKER_HOST_ROOTLESS_PATH=

bin/fresh-start.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ while [[ $# -gt 0 ]]; do
429429
shift 1
430430
;;
431431

432+
# Docker rootless support
433+
-dr)
434+
USE_DOCKER_ROOTLESS=true
435+
shift 1
436+
;;
437+
--docker-rootless)
438+
USE_DOCKER_ROOTLESS=true
439+
shift 1
440+
;;
441+
432442
# IPv4 options
433443
--ipv4-subnet=*)
434444
ARG_IPv4_SUBNET="${1#*=}"
@@ -1121,6 +1131,16 @@ DOCKER_HTTPS=${ARG_DOCKER_HTTPS:-"443"}
11211131
#-----------------------------------------------------------------------
11221132
SSL_POLICY=${ARG_SSL_POLICY:-"Mozilla-Intermediate"}
11231133

1134+
#-----------------------------------------------------------------------
1135+
# Docker rootless support. Add the current user's docker.sock path (default: blank)
1136+
# Please read the official documentation of installing Docker Rootless:
1137+
# https://docs.docker.com/engine/security/rootless/
1138+
#-----------------------------------------------------------------------
1139+
if [[ "$USE_DOCKER_ROOTLESS" == true ]]; then
1140+
# Get the current user's $XDG_RUNTIME_DIR and concat with the '/docker.sock'
1141+
DOCKER_HOST_ROOTLESS_PATH=`echo ${XDG_RUNTIME_DIR}/docker.sock`
1142+
fi
1143+
11241144
#-----------------------------------------------------------------------
11251145
# Start actions!
11261146
#-----------------------------------------------------------------------

bin/localscript/update-env-new-site-variables.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@ local_update_env_new_site_variables()
7878
# Default host
7979
[[ ! $ARG_DEFAULT_HOST == "" ]] && run_function env_update_variable $LOCAL_FILE_PATH "DEFAULT_HOST" "${ARG_DEFAULT_HOST}"
8080

81+
# Docker rootless support
82+
run_function env_update_variable $LOCAL_FILE_PATH "DOCKER_HOST_ROOTLESS_PATH" "$DOCKER_HOST_ROOTLESS_PATH"
83+
8184
return 0
8285
}

bin/localscript/usage-fresh-start.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Usage:
6464
[--use-nginx-conf-files] [--update-nginx-template]
6565
[--yes]
6666
[--debug]
67+
[--docker-rootless]
6768
6869
Required
6970
-e | --default-email Default email address require to issue ssl
@@ -131,6 +132,10 @@ Usage:
131132
--yes Set "yes" to all, use it with caution
132133
--debug Show script debug options
133134
--silent Hide all script message
135+
-dr | --docker-rootless Add Docker rootless support by adding the
136+
the current user's $XDG_RUNTIME_DIR and
137+
concat with the '/docker.sock' in the
138+
DOCKER_HOST_ROOTLESS_PATH .env file.
134139
-h | --help Display this help
135140
136141
${reset}

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
- ${NGINX_FILES_PATH:-./data}/html:/usr/share/nginx/html
4040
- ${NGINX_FILES_PATH:-./data}/certs:/etc/nginx/certs:ro
4141
- ${NGINX_FILES_PATH:-./data}/htpasswd:/etc/nginx/htpasswd:ro
42-
- /var/run/docker.sock:/tmp/docker.sock:ro
42+
- ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:/tmp/docker.sock:ro
4343
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
4444
logging:
4545
driver: ${NGINX_GEN_LOG_DRIVER:-json-file}
@@ -57,7 +57,7 @@ services:
5757
- ${NGINX_FILES_PATH:-./data}/html:/usr/share/nginx/html
5858
- ${NGINX_FILES_PATH:-./data}/certs:/etc/nginx/certs:rw
5959
- ${NGINX_FILES_PATH:-./data}/acme.sh:/etc/acme.sh
60-
- /var/run/docker.sock:/var/run/docker.sock:ro
60+
- ${DOCKER_HOST_ROOTLESS_PATH:-/var/run/docker.sock}:/var/run/docker.sock:ro
6161
environment:
6262
NGINX_DOCKER_GEN_CONTAINER: ${DOCKER_GEN_SEVICE_NAME:-nginx-proxy-automation-gen}
6363
NGINX_PROXY_CONTAINER: ${NGINX_WEB_SEVICE_NAME:-nginx-proxy-automation-web}

0 commit comments

Comments
 (0)