Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory (Alpine linux docker image)

I can not install ruby's gems on alpine docker image. I've tried different approaches from other questions to solve ERROR: While executing gem ... (Gem::FilePermissionError), but there are solutions either for Ubuntu or for Mac OS.

Part of docker file code:

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

OUTPUT:

+ 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 ```

like image 551
Jeremy Avatar asked Jul 04 '21 08:07

Jeremy


1 Answers

This seems to be a problem with docker versions earlier than 20.10.4, and at the time of writing this, DockerHub runs an older version.

Option 1:

If you have control over the version of your docker engine, upgrade it to the latest version (comments suggest at least version 20.10.4).

Option 2:

Use FROM alpine:3.13.

With the latest alpine (3.14) it breaks.

Option 3:

Use the official ruby alpine image. I tested with FROM ruby:3-alpine.

References:

  • The issue opened on alpine/aports
  • The relevant release notes section for alpine 3.14
like image 197
DannyB Avatar answered Oct 19 '22 13:10

DannyB