-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Files generated within the docker container should belong to the host user #2284
Comments
One example i use: For container itself - gosu might do the trick, used in entrypoint, while also passing current user id from docker-compose file. P.S. During local development I actually run all management commands locally, not in docker. This is very broad issue of local vs docker.
This brings advantage of local shell, which I am still in process of customizing, using vim, simplifies using other system tools. Docker in such case is just a tool of installing software - i can either install db / redis system-wide (which may be not so simple, and is different on different os), probably bound to only one version / instance, or i can run multiple versions with docker. Not all devs know docker, such setup allows running management commands, heck, all commands, both in docker or locally, with only starting required services (db / redis) in docker, which is far simpler, pycharm has hooks to autostart containers on project load. Good discussion with example of dev environment with vim and other tools in docker - looks nice and feels worth trying, although i think its more personal tool and requires some understanding of what's under the hood. |
Usage with /gosu-entrypoint#!/bin/sh
set -eu
EUID=1000
EGID=1000
# Setting user and group id based on manage.py file owner
if [ -f "manage.py" ]; then
EUID=$(stat -c %u manage.py)
EGID=$(stat -c %g manage.py)
fi
# Creating user and group django with required ids, needed by some libs
if ! getent passwd django > /dev/null; then
addgroup -g $EGID django
adduser -h /app -H -u $EUID -G django -s /bin/bash -D -g DJANGO django
fi
exec gosu django:django "$@" |
Description
In docker development in Linux (and Mac?) when a file is generated in the docker container, it belongs to the root user. Since the project directory is a volume to the host machine directory, those files belong to the root user in the host as well. If you want to edit those files, you need to become root or change the permissions. It would be nice to not have to deal with this.
Examples of iles that are generated by the application:
This does not only apply to editing the files; sometimes permissions cause problems when rebuilding an image.
Rationale
Removing the need to deal with permissions will improve the development workflow
Suggestion
Without being an expert on the subject, I deal with this problem by assigning user 1000 to the container. However, I think this does not generalize since not all users will have the id 1000. Also I am not sure if this conflicts with #1410
The text was updated successfully, but these errors were encountered: