We’re working with Windows and Mac M1 machines to develop locally using Docker and need to fetch and install a .deb package within our docker environment.
The package needs amd64/arm64 depending on the architecture being used.
Is there a way to determine this in the docker file i.e.
if xyz === 'arm64'
RUN wget http://...../arm64.deb
else
RUN wget http://...../amd64.deb
2
Answers
First you need to check if there is no other (easier) way to do it with the package manager.
You can use the
arch
command to get the architecture (equivalent touname -m
). The problem is that it does not return the values you expect (aarch64
instead ofarm64
andx86_64
instead ofamd64
). So you have to convert it, I have done it through ased
.Note: You should add the following code before running this command to prevent unexpected behavior in case of failure in the piping chain. See Hadolint
DL4006
for more information.Later versions of Docker expose info about the current architecture using global variables:
Note that you may need to
export DOCKER_BUILDKIT=1
on headless machines for these to work, and they are enabled by default on Docker Desktop.Use in conditional scripts like so:
You can even branch Dockerfiles by using ONBUILD like this: