|
188 | 188 | TARGET_COMPOSE_ARCH="x86_64"
|
189 | 189 | fi
|
190 | 190 | if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; then
|
191 |
| - # Use pip to get a version that runs on this architecture |
| 191 | + # Use pip to get a version that runns on this architecture |
192 | 192 | if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then
|
193 | 193 | apt_get_update_if_needed
|
194 | 194 | apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
|
@@ -232,6 +232,13 @@ if [ "${ENABLE_NONROOT_DOCKER}" = "false" ] || [ "${USERNAME}" = "root" ]; then
|
232 | 232 | exit 0
|
233 | 233 | fi
|
234 | 234 |
|
| 235 | +# Setup a docker group in the event the docker socket's group is not root |
| 236 | +if ! grep -qE '^docker:' /etc/group; then |
| 237 | + groupadd --system docker |
| 238 | +fi |
| 239 | +usermod -aG docker "${USERNAME}" |
| 240 | +DOCKER_GID="$(grep -oP '^docker:x:\K[^:]+' /etc/group)" |
| 241 | + |
235 | 242 | # If enabling non-root access and specified user is found, setup socat and add script
|
236 | 243 | chown -h "${USERNAME}":root "${TARGET_SOCKET}"
|
237 | 244 | if ! dpkg -s socat > /dev/null 2>&1; then
|
@@ -271,20 +278,13 @@ log()
|
271 | 278 | echo -e "\n** \$(date) **" | sudoIf tee -a \${SOCAT_LOG} > /dev/null
|
272 | 279 | log "Ensuring ${USERNAME} has access to ${SOURCE_SOCKET} via ${TARGET_SOCKET}"
|
273 | 280 |
|
274 |
| -# If enabled, try to add a docker group with the right GID. If the group is root, |
| 281 | +# If enabled, try to update the docker group with the right GID. If the group is root, |
275 | 282 | # fall back on using socat to forward the docker socket to another unix socket so
|
276 | 283 | # that we can set permissions on it without affecting the host.
|
277 | 284 | if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${USERNAME}" != "root" ] && [ "${USERNAME}" != "0" ]; then
|
278 | 285 | SOCKET_GID=\$(stat -c '%g' ${SOURCE_SOCKET})
|
279 |
| - if [ "\${SOCKET_GID}" != "0" ]; then |
280 |
| - log "Adding user to group with GID \${SOCKET_GID}." |
281 |
| - if [ "\$(cat /etc/group | grep :\${SOCKET_GID}:)" = "" ]; then |
282 |
| - sudoIf groupadd --gid \${SOCKET_GID} docker-host |
283 |
| - fi |
284 |
| - # Add user to group if not already in it |
285 |
| - if [ "\$(id ${USERNAME} | grep -E "groups.*(=|,)\${SOCKET_GID}\(")" = "" ]; then |
286 |
| - sudoIf usermod -aG \${SOCKET_GID} ${USERNAME} |
287 |
| - fi |
| 286 | + if [ "\${SOCKET_GID}" != "0" ] && [ "\${SOCKET_GID}" != "${DOCKER_GID}" ]; then |
| 287 | + sudoIf groupmod --gid "\${SOCKET_GID}" "${USERNAME}" |
288 | 288 | else
|
289 | 289 | # Enable proxy if not already running
|
290 | 290 | if [ ! -f "\${SOCAT_PID}" ] || ! ps -p \$(cat \${SOCAT_PID}) > /dev/null; then
|
|
0 commit comments