-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Permissions in docker-entrypoint.sh #321
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
Comments
We did discuss this when we moved to allow the container to run as (semi) arbitrary users: #253 (comment) and have a note in the docs:
Is there a reason you don't just Just a reminder that any scripts or sql files in As long as it doesn't need postgres running, perhaps your script just needs to run before the entrypoint? Just end your script with FROM postgres:9.5
....
COPY ./init.sh /usr/local/bin/
# some docker storage backends fail on this kind of layer, so should probably chmod it in git instead
RUN chmod +x /usr/local/bin/init.sh
ENTRYPOINT ["init.sh"]
CMD ["docker-entrypoint.sh", "postgres"] |
Hello @yosifkit, first of all thank you for your support! The Thank you for this
The whole idea was to move/delete files after being used, so a restart wouldn't trigger the same behavior. Since this only happens once, I can import them directly from the volume, so I ended up doing this in the
I think you can close this issue. But, in my humble opinion, I don't think the entrypoint scripts and SQL files should run within a user with so few permissions. Maybe right before starting the postgres, u could login as postgres user. I understand the security constraints, but, at the end of the day I can do a |
Anybody interested in solving this thing by mounting a directory and not relying onto COPY or ADD, this might be useful. Also as documentation for my future self. Given we have a init.d directory, with one or more init scripts, we can do following dance: # get the user ID of the user running the process
docker top eremite-postgresql-16
# was 999 for the process postgres
# get the user name
docker exec -it eremite-postgresql-16 /bin/bash
cat /etc/passwd | grep 999
# got the line for the user postgres for the group id
cat /etc/group | grep postgres
# hence, this is what we want: 999:999
exit
sudo chown 999:999 initdb.d/*
chmod u+x initdb.d/* Enjoy :) |
I'm trying to execute a simple script, but it seems I don't have enough permissions with postgres user, specially to create folders. Shouldn't the entrypoint script be executed as root? So it can be possible to do anything with my scripts?
The idea around this is to automatically add .sql files to the init folder, but I don't want to edit the Dockerfile and place a COPY each time I have a new sql file to execute.
This is a simple example to illustrate the problem, the real init.sh is supposed to copy files from a Volume to the right folder, but the copy doesn't have enough permissions, just like the mkdir in the example bellow:
Dockerfile
init.sh
Result
The text was updated successfully, but these errors were encountered: