I know that running docker containers as root is not secure, so I would like to change they way I run them. I have a container running postgres, which up till now was run as root (default). However, when I add this line to my docker-compose file:
user: ${CURRENT_UID}
Where CURRENT_UID is:
export CURRENT_UID=$(id -u):$(id -g)
I get the following error in the container logs:
initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
fixing permissions on existing directory /var/lib/postgresql/data ... chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
chmod: changing permissions of '/var/run/postgresql': Operation not permitted
The situation is the same when running the pg-admin container, with the error message:
PermissionError: [Errno 13] Permission denied: '/var/log/pgadmin'
The errors make sense of course, I am non root, yet postgres requires root access.
Does it mean it is impossible to run as non root?