我知道以 root 身份运行 docker 容器并不安全,所以我想改变它们的运行方式。我有一个运行 postgres 的容器,到目前为止它是以 root 身份运行的(默认)。但是,当我将这一行添加到我的docker-compose文件中时:
user: ${CURRENT_UID}
Run Code Online (Sandbox Code Playgroud)
哪里CURRENT_UID:
export CURRENT_UID=$(id -u):$(id -g)
Run Code Online (Sandbox Code Playgroud)
我在容器日志中收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
运行容器时情况也是一样pg-admin,报错信息:
PermissionError: [Errno 13] Permission denied: '/var/log/pgadmin'
Run Code Online (Sandbox Code Playgroud)
这些错误当然是有道理的,我不是 root,但 postgres 需要 root 访问权限。
这是否意味着无法以非 root 身份运行?