I have a Dockerfile to build a Docker image that is based on Alpine Linux. Now I need to install a package as part of this Dockerfile.
Currently I have:
RUN apk update && \
apk upgrade && \
apk add git
Apparently this is a bad idea, as the result is non-deterministic. Instead, it depends on the point in time at which I build the image, which version of git is getting installed.
What is the correct way of doing this?
I guess that I have to tell updated, upgrade and add which versions to use, but how do I do this?
I have seen that apk supports pinning of repositories, but that is not what I want (at least I think so), because I do not want to pin a repository, but a package.
In other words: If git could be installed via npm, I'd be able to run:
npm install git@1.9.2
(or whatever version I want to have). What is the equivalent to this for Alpine Linux?

apk add ansible~=2.4.1meaning>=2.4.1 <2.5.0. Check out http://jubianchi.github.io/semver-check to test your own ranges. – Mike D May 13 '18 at 12:17apk add samba~=4.14.8-r0didn't work (with or without the-r0) when only4.14.12-r0was available - howeverapk add samba~=4.14did work. The former should work AFAICS but either way posting this in case it helps anyone - i.e. you may need to omit the patch portion of the version. – sparrowt Mar 01 '22 at 13:03