ruby应用程序Dockerfile中的文件权限问题

ruby应用程序Dockerfile中的文件权限问题,ruby,permissions,dockerfile,Ruby,Permissions,Dockerfile,你好,我正在尝试使用容器中的用户id和组id创建一个ruby应用程序,就像在主机中一样,即1000 我遇到权限问题,但我不知道为什么 以下是我得到的错误: There was an error while trying to write to `/home/appuser/myapp/Gemfile.lock`. It is likely that you need to grant write permissions for that path. The command '/bin/sh -c

你好,我正在尝试使用容器中的用户id和组id创建一个ruby应用程序,就像在主机中一样,即1000

我遇到权限问题,但我不知道为什么

以下是我得到的错误:

There was an error while trying to write to `/home/appuser/myapp/Gemfile.lock`.
It is likely that you need to grant write permissions for that path.
The command '/bin/sh -c bundle install' returned a non-zero code: 23
这是我的Dockerfile:

# Dockerfile
FROM ruby:2.5

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

RUN groupadd -r -g 1000 appuser
RUN useradd -r -m -u 1000 -g appuser appuser
USER appuser

RUN mkdir /home/appuser/myapp

WORKDIR /home/appuser/myapp

COPY Gemfile Gemfile.lock ./

RUN bundle install

COPY . ./

如果您想要纯docker解决方案,请尝试以下方法:

FROM ruby:2.5

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

# Reduce layers by grouping related commands into single RUN steps
RUN groupadd -r -g 1000 appuser && \
useradd -r -m -u 1000 -g appuser appuser

# Setting workdir will also create the dir if it doesn't exist, so no need to mkdir
WORKDIR /home/appuser/myapp

# Copy everything over in one go
COPY . ./

# This line should fix your issue 
# (give the user ownership of their home dir and make Gemfile.lock writable)
# Must still be root for this to work
RUN chown -R appuser:appuser /home/appuser/ && \
chmod +w /home/appuser/myapp/Gemfile.lock

USER appuser

RUN bundle install
使用以下内容修复主机系统上的权限可能是一个更好的主意:

sudo chmod g+w Gemfile.lock

WORKDIR/home/appuser/myapp
之后运行ls-la.会打印出什么?@mudasobwa它打印出来:
drwxr-xr-x2 appuser-appuser 4096 Aug 24 09:01。
drwxr-xr-x3 appuser-appuser 4096 Aug 24 09:01。chmod-R+w/home/appuser/myapp应该这样做。您需要在更改为appuser之前运行它,或者在运行BuildUser之前修改系统上的文件。谢谢<代码>sudo chmod g+w Gemfile.lock修复了它!