Alpine linux install specific (older) package version
At my project I use Docker-in-Docker images for GitLab CI.
And those are only Alpine-based.
And for some another dependency I needed a very specific version of openssh package installed. An older one. And I could not downgrade the whole version of Alpine I use.
And Alpine does not really allow you to install the older package versions in a way that e.g. Debian-based distros do when you can hook in another version repo and install from it (which is still not exactly recommended).
Long story short, what you CAN do is — build the needed package from source code and install it!
First — go to https://pkgs.alpinelinux.org/packages and find which Alpine version (branch) has the package version you need:
Then in your main Alpine version do this:
# Install the build prerequisites.apk add alpine-sdk sudo# Create user and add it to the group.
# Because root can not build packages.adduser -D packager && addgroup packager abuild# Give him sudo access.echo 'packager ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/packager# Switch to that usersu packager# Clone aports repo with the sources of all Alpine packages.git clone git://git.alpinelinux.org/aports# cd into your package dircd ~/aports/main/openssh# Switch to the branch you found at the website.git checkout 3.7-stable# Create a signature certificate and build the package!abuild-keygen -a -i -n && abuild -r# Exit from the packager user back to root:exit # or ctrl+d# Find the package and install it:cd /home/packager/packages/main/x86_64/ && apk add openssh-7.5_p1-r10.apk openssh-client-7.5_p1-r10.apk
And this can also be neatly wrapped into a single Docker layer command where we also do some cleanup at the end:
RUN apk add alpine-sdk sudo && \
adduser -D packager && addgroup packager abuild && \
echo 'packager ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/packager && \
su - packager -c 'git clone git://git.alpinelinux.org/aports && \
cd ~/aports/main/openssh && \
git checkout 3.7-stable && \
abuild-keygen -a -i -n && \
abuild -r' && \
cd /home/packager/packages/main/x86_64/ && \
apk add openssh-7.5_p1-r10.apk openssh-client-7.5_p1-r10.apk && \
apk del alpine-sdk sudo
Ciao and good luck!