← Back Home

Add Older Version Packages to Alpine

  1. til
  2. alpine
  3. ruby
  4. image upgrade

At work, we use Ruby 2.5.8 and the base image was alpine:3.10. We wanted to upgrade the base image to alpine:3.12.

First attempt

1
2
FROM alpine:3.12 as base
RUN apk add --no-cache ruby
ends up installing Ruby 2.7.1-r3.

Second Attempt

Then I try to pin the package version like

1
2
FROM alpine:3.12 as base
RUN apk add --no-cache ruby=2.5.8
but that results in this error output

1
2
3
ERROR: unsatisfiable constraints:
   ruby-2.7.1-r3:
     breaks: world[ruby=2.5.8]

Solution

To fix this, we need to add the add the repository containing the package version in /etc/apk/repositories and then install the pinned version. Also add the --update option to apk add.

1
2
FROM alpine:3.12 as base
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.10/main" >> /etc/apk/repositories && apk add --no-cache --update ruby=2.5.8