Using different package repositories with Alpine Linux

2023-05-04 Last modified on 2023-05-04

As described in the Alpine Linux wiki, there are 3 package repositories: main, community and testing.

Looking for the kubectl package, we see that it is part of the "testing" repository.

This means that using the following results in an error (cleaned up for readability):

 > [stage-1 2/6] RUN apk --no-cache add ca-certificates kubectl helm:
#0 2.454 fetch
#0 2.968 fetch
#0 5.994 ERROR: unable to select packages:
#0 6.065   kubectl (no such package):
#0 6.065     required by: world[kubectl]

Looking at the wiki page linked before, I thought I would have to add the "testing" repository to the list of repositories, which is not super convenient.

There is another way, we can install the package like this, passing the repository as a parameter:

apk add --no-cache -X kubectl

Adding the repository to the mirrors list would be better for multiple packages, but in my case it is good enough.