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

Stark
  • 336
  • 1
  • 3
  • 14
  • 1
    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. – DannyB Jul 05 '21 at 13:33
  • 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? – DannyB Jul 05 '21 at 14:05
  • @DannyB Yes, I have the same fails with 3.14. It looks strange – Stark Jul 06 '21 at 05:37

1 Answers1

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:

DannyB
  • 12,810
  • 5
  • 55
  • 65
  • 1
    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. – DannyB Jul 12 '21 at 14:55
  • 5
    I ran into the same issue with builds on CircleCI and fixed it by updating the Docker version used to 20.10.6 – m90 Jul 15 '21 at 06:28
  • 2
    Thanks for confirming @m90, I have updated the answer with "upgrade docker" solution. – DannyB Jul 15 '21 at 07:08
  • 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. – Jakob Rasmussen Sep 10 '21 at 08:57
  • 1
    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. – Shawn Deprey Feb 11 '22 at 22:13
  • 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. – DannyB Feb 12 '22 at 12:19
  • 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. – Archonic Jul 20 '22 at 22:56
  • nice. in circleci looks like this: - setup_remote_docker: version: 20.10.14 – Jake Aug 18 '22 at 17:57
  • 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. – Nathan McKaskle Jan 25 '23 at 15:18