Created
November 12, 2015 14:09
-
-
Save nmajor/8168101b00270ebd5f0d to your computer and use it in GitHub Desktop.
Startup script for docker containers to resolve volume permission issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Original source of this script: http://stackoverflow.com/questions/23544282/what-is-the-best-way-to-manage-permissions-for-docker-shared-volumes/28596874#28596874 | |
# This will only work for files and folders that allow the group to do what they are trying to do. Wont work on files with 700 permissions for instance. | |
# Path of mounted volume inside the container | |
VOLUME_PATH = change/me/path | |
# Name of user that needs permissions to the volume | |
USERNAME = changme | |
# Get the guid of the directory used for the shared volume | |
TARGET_GID=$(stat -c "%g" /volume/FOOBAR) | |
# Check if a group exists with the same guid within the container | |
EXISTS=$(cat /etc/group | grep $TARGET_GID | wc -l) | |
# Create new group using target GID and add nobody user | |
if [ $EXISTS == "0" ]; then | |
groupadd -g $TARGET_GID tempgroup | |
usermod -a -G tempgroup nobody | |
else | |
# GID exists, find group name and add | |
GROUP=$(getent group $TARGET_GID | cut -d: -f1) | |
usermod -a -G $GROUP $USERNAME | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment