Install older package version in Alpine

Viewed 9857

So recently (5th September) the Alpine Linux package repo was updated to postgresql-client 12.4

I'm referencing version 12.3 in my Dockerfile (apk add postgresql-client=~12.3). Is it not possible to install that version now?

I'd like to update on my time and terms, why should I be forced to update now? Is there another repository I can add to use the older version?

Thanks

3 Answers

Unfortunately, Alpine packages are always updated in place to the latest version, and older versions are discarded. This could be painful, indeed...

Usually, when a package is updated, it's updated with all Alpine distro versions that it's compatible to. For example, postgresql-client was bumped to 12.4-r0 on edge, v3.12 and v3.11, but on Alpine v3.10 repos you'll still find 11.9-r0. In case this was enough, the old version could be installed from the desired repository, as long as it lasts, using:

apk add postgresql-client=11.9-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.10/main

However, since 12.3 doesn't live in the official Alpine repositories anymore, you could rely on an external Docker image, instead.

Luckily, the postgres official images has version tags, and you can find the desired Alpine image for 12.3:

$ wget -q https://registry.hub.docker.com/v1/repositories/postgres/tags -O - | jq -r '.[].name' | grep 12.3
12.3  
12.3-alpine

Therefore, you can use FROM:postgres:12.3-alpine to get the desired version from.

In tougher cases, where the Alpine package version is updated, and couldn't be found in other images, the only resort may be building from source.

Another solution based on the answer of @valiano.

For upgrading postgresql to a newer version, it is recommended to use the higher version pg_dump binaries. But how to get these into your image? This works for me:

Dockerfile:

ARG VERSION=10
ARG UPGRADE_VERSION=11
ARG TYPE
###############################################################
# Normal server
###############################################################
FROM postgres:${VERSION}-alpine AS server

RUN apk update \
 && apk add --upgrade apk-tools \
 && apk upgrade --available

COPY /rootfs/ /

###############################################################
# Upgrade version with upgrade executables
###############################################################
FROM postgres:${UPGRADE_VERSION}-alpine AS upgrade_version
RUN apk update \
 && apk add --upgrade apk-tools \
 && apk upgrade --available

###############################################################
# Add postgresql upgrade client executables to upgrade_server_layer
###############################################################
FROM server AS upgrade_server

RUN mkdir -p /usr/local/postgresql/upgrade
COPY --from=upgrade_version /usr/local/bin/pg* /usr/local/postgresql/upgrade/

###############################################################
# Final version
###############################################################
FROM ${TYPE}server AS final

Then build your normal server as:

docker build --build-arg TYPE= --build-arg VERSION=11 --build-arg UPGRADE_VERSION=12 -t my_normal_server:11 .

And a server with upgrade binaries, to make the dumpfile:

docker build --build-arg TYPE=upgrade_ --build-arg VERSION=10 --build-arg UPGRADE_VERSION=11 -t my_upgrade_server:10 .

Upgrade scenario if current version is postgresql 10 and you want to upgrade to 11:

  1. Build an upgrade version and a normal version.
  2. Stop the postgresql 10 container and replace it with the my_upgrade_version:10
  3. Create a dumpfile with the /usr/local/postgresql/upgrade/pg_dump.
  4. Create a new postgresql 11 container with my_normal_version:11 with access to the dumpfile and use pg_restore to restore the created dumpfile.

for example; the latest dnsmasq version ins 2.84-r0 at now, if you install 2.83-r0, will:

$ docker run --rm -ti alpine:3.13
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch https://mirrors.aliyun.com/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  dnsmasq-dnssec-2.84-r0:
    breaks: world[dnsmasq-dnssec=2.83-r0]

The best thing you can achieve is using repositories of the earlier releases, at the websiete https://pkgs.alpinelinux.org/packages to search the old version, will find 2.83-r0 in https://pkgs.alpinelinux.org/packages?name=dnsmasq&branch=v3.12. so add the old repo

$ echo 'http://dl-cdn.alpinelinux.org/alpine/v3.12/main' >> /etc/apk/repositories
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch http://mirrors.aliyun.com/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.aliyun.com/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/3) Installing gmp (6.2.0-r0)
(2/3) Installing nettle (3.5.1-r1)
(3/3) Installing dnsmasq-dnssec (2.83-r0)
Executing dnsmasq-dnssec-2.83-r0.pre-install
Executing busybox-1.31.1-r16.trigger
OK: 7 MiB in 17 packages
Related