您没有 /usr/lib/ruby/gems/2.7.0 目录的写入权限(Alpine linux docker 图像)
You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory (Alpine linux docker image)
我无法在 alpine docker 图像上安装 ruby 的 gems。我尝试了与其他问题不同的方法来解决 ERROR: While executing gem ... (Gem::FilePermissionError)
,但是 Ubuntu 或 Mac OS.
都有解决方案
部分docker文件代码:
RUN set -ex \
&& apk add --no-cache --update ruby ruby-dev ruby-bundler \
&& gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
输出:
+ apk add --no-cache --update ruby ruby-dev ruby-bundler
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/11) Installing yaml (0.2.5-r0)
(2/11) Installing ruby-libs (2.7.3-r1)
(3/11) Installing ruby (2.7.3-r1)
(4/11) Installing ruby-etc (2.7.3-r1)
(5/11) Installing ruby-io-console (2.7.3-r1)
(6/11) Installing ruby-bundler (2.2.20-r0)
(7/11) Installing libgmpxx (6.2.1-r0)
(8/11) Installing gmp-dev (6.2.1-r0)
(9/11) Installing libucontext (1.1-r0)
(10/11) Installing libucontext-dev (1.1-r0)
(11/11) Installing ruby-dev (2.7.3-r1)
Executing busybox-1.33.1-r2.trigger
Executing glibc-bin-2.33-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/glibc-compat/lib/ld-linux-x86-64.so.2 is not a symbolic link
OK: 1409 MiB in 141 packages
+ gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
The command '/bin/sh -c set -ex && apk add --no-cache --update ruby ruby-dev ruby-bundler && gem install --no-document --source https://rubygems.org --version 3.6.6 inspec' returned a non-zero code: 1 ```
这似乎是 docker 早于 20.10.4
的版本的问题,在撰写本文时,DockerHub 运行的是旧版本。
选项 1:
如果您可以控制 docker 引擎的版本,请将其升级到最新版本(评论建议至少版本 20.10.4
)。
选项 2:
使用FROM alpine:3.13
.
最新的 alpine (3.14
) 它坏了。
选项 3:
使用官方 ruby alpine 图像。我用 FROM ruby:3-alpine
.
测试过
参考文献:
我无法在 alpine docker 图像上安装 ruby 的 gems。我尝试了与其他问题不同的方法来解决 ERROR: While executing gem ... (Gem::FilePermissionError)
,但是 Ubuntu 或 Mac OS.
部分docker文件代码:
RUN set -ex \
&& apk add --no-cache --update ruby ruby-dev ruby-bundler \
&& gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
输出:
+ apk add --no-cache --update ruby ruby-dev ruby-bundler
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/11) Installing yaml (0.2.5-r0)
(2/11) Installing ruby-libs (2.7.3-r1)
(3/11) Installing ruby (2.7.3-r1)
(4/11) Installing ruby-etc (2.7.3-r1)
(5/11) Installing ruby-io-console (2.7.3-r1)
(6/11) Installing ruby-bundler (2.2.20-r0)
(7/11) Installing libgmpxx (6.2.1-r0)
(8/11) Installing gmp-dev (6.2.1-r0)
(9/11) Installing libucontext (1.1-r0)
(10/11) Installing libucontext-dev (1.1-r0)
(11/11) Installing ruby-dev (2.7.3-r1)
Executing busybox-1.33.1-r2.trigger
Executing glibc-bin-2.33-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/glibc-compat/lib/ld-linux-x86-64.so.2 is not a symbolic link
OK: 1409 MiB in 141 packages
+ gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
The command '/bin/sh -c set -ex && apk add --no-cache --update ruby ruby-dev ruby-bundler && gem install --no-document --source https://rubygems.org --version 3.6.6 inspec' returned a non-zero code: 1 ```
这似乎是 docker 早于 20.10.4
的版本的问题,在撰写本文时,DockerHub 运行的是旧版本。
选项 1:
如果您可以控制 docker 引擎的版本,请将其升级到最新版本(评论建议至少版本 20.10.4
)。
选项 2:
使用FROM alpine:3.13
.
最新的 alpine (3.14
) 它坏了。
选项 3:
使用官方 ruby alpine 图像。我用 FROM ruby:3-alpine
.