-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create mounted volumes before running docker
If we mount to a directory the doesn't exist, docker will create the local directory. If we let docker create the directories, it will create it owned by root-user, and then the container won't be able to write to the directory. By creating them in-advance, we make them owned by the user, and the container can write to them. BTW - This solves the problem with 'go build' not being able to write to the 'gocache' directory.
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,23 @@ def _run_nested(fqdn_image, environment, command, interactive, name, net, volume | |
'/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z', | ||
]) | ||
for volume in volumes: | ||
if ":" not in volume: | ||
raise ValueError("Volume entry is badly-formatted - %s" % volume) | ||
|
||
# If the local directory of a mount entry doesn't exist, docker will by | ||
# default create a directory in that path. Docker runs in systemd context, | ||
# with root-privileges, so the container will have no permissions to write | ||
# to that directory. To prevent that, we'll create the directory in advance, | ||
# with the user's permissions | ||
localdir = volume.split(":")[0] | ||
if not os.path.exists(localdir.strip()): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
spellr
Author
Contributor
|
||
try: | ||
os.makedirs(localdir) | ||
except OSError: | ||
# If we have no permissions to create the directory, we'll just let | ||
# docker create it with root-privileges | ||
pass | ||
|
||
docker_cmd += ['-v', volume] | ||
|
||
if workdir: | ||
|
What will be the behaviour if we are mounting a file and not a folder?