非特权 docker 图像中的权限被拒绝

Permission denied in unprivileged docker image

我正在尝试 运行 具有严格安全措施的 Kubernetes 集群上的 rethinkdb 映像,我们必须 运行 容器作为非 root,因此我使用用户 1000 到 运行 他们和我将 Dockerfile 更改为以下内容:

FROM ubuntu:18.04

RUN apt update && apt install -y wget libcurl4 libprotobuf10 python3-pip

RUN wget https://github.com/srh/rethinkdb/releases/download/v2.3.6.srh.1/rethinkdb_2.3.6.srh.1.0bionic_amd64.deb
RUN dpkg -i rethinkdb_2.3.6.srh.1.0bionic_amd64.deb

ADD rethinkdb_tables /opt/rethinkdb_tables
RUN pip3 install rethinkdb==2.3

ADD entry_point.sh /opt/entry_point.sh

ENV RUN_ENV docker-compose

RUN id
RUN apt-get update && apt-get install -y sudo
RUN groupadd newuser
RUN useradd -u 1000 -m -g newuser newuser
RUN adduser newuser sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN mkdir /data
RUN chown -R newuser:0 /opt/
RUN chown -R newuser:0 /data
USER newuser

ENTRYPOINT [ "sh", "/opt/entry_point.sh" ]
CMD []

entry_point.sh 是一个启动 rethinkdb 的小脚本,一旦 rethinkdb 启动,它就会导入一些表。但我遇到以下错误:

Launch rethinkdb in Kubernetes
Could not create directory 'rethinkdb_data': Permission denied

我该如何解决这个问题?我不得不提的是,这是我过去 运行 我的其他图像作为非 root 的方式,这对他们有用。

由于 rethinkdb 想在 / 创建 rethinkdb_data,我决定自己在 Dockerfile 中创建该目录并更改其所有者,以便 rethinkdb 可以访问它,这解决了我的问题。