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

1

12

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

Yoheaveho answered 4/7, 2021 at 8:45 Comment(3)
This is weird, I am also suddenly facing the same issue on an image that builds locally without a problem, and used to build on dockerhub without a problem. I will post here if I find a solution.Rainband
Although I have not yet found the reason, I see that with alpine 3.13 it builds properly on dockerhub, and alpine 3.14 fails. Can you confirm?Rainband
@Rainband Yes, I have the same fails with 3.14. It looks strangeYoheaveho
R
20

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:

Rainband answered 5/7, 2021 at 15:26 Comment(9)
I found out this is a problem that was solved in the recent docker engine, which is not yet used in DockerHub. Updated the answer accordingly, for posterity.Rainband
I ran into the same issue with builds on CircleCI and fixed it by updating the Docker version used to 20.10.6Insert
Thanks for confirming @m90, I have updated the answer with "upgrade docker" solution.Rainband
To fine grain this even more I can tell we have the exact same error on version 20.10.3 but upgrade to 20.10.8 fixed it, so I don't think it's related to versions prior 20.10.0.Cumulus
Updating docker did resolve this issue for me, however, I ran into the same issue on 20.10.2 as @JakobRasmussen did on a similar dot version above. I updated to Docker version 20.10.12, build e91ed57 and it resolved the issue for me.Mesothorium
I updated the answer to reflect the lowest known version to fix that, although I believe that people who reach this problem should simply upgrade docker to the latest version.Rainband
I'm using the official ruby alpine image (tag: ruby:3.0.4-alpine3.16) and it's hit the same issue. I believe official ruby images haven't done anything specific to remedy this.Placement
nice. in circleci looks like this: - setup_remote_docker: version: 20.10.14Upthrow
This is happening to me in docker engine 20.10.22 so it's not the docker engine. I am trying to build this image off the latest phusion/passenger base.Ynes

© 2022 - 2024 — McMap. All rights reserved.