gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:55:18 24 4
gpt4 key购买 nike

你好,我正在尝试使用容器中的用户 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

关于ruby - ruby 应用程序的 Dockerfile 中的文件权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52001025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com