As the official docker alpine repository got multi-architecture support, How can I get the architecture name within the base image, especially in Dockerfile?
https://github.com/docker-library/official-images#architectures-other-than-amd64
Only getting the system is 32bit or 64bit is not good enough. I prefer the result to be the same as the docker architectures, like arm32v7, arm64v8, amd64, etc.
My goal is to bulid a nodejs docker image. For amd64, most dependences are available directly, while for some other architectures, they need to be compiled from source, in which case extra deps like python, gcc/g++ are required. I wish my script in dockerfile can figure it out and only install these extra deps only when necessary.
Image recipes for different architectures have their own Dockerfiles, so it's just a matter of picking the right one to work with (hope I got your question right).
There are available Node images for Alpine targeting various architectures, for example:
sudo docker pull ppc64le/node:8-alpine
Is the Node.js 8.12.0 image for PPC64LE on Alpine 3.8.
Edit after clarification:
For a multiarch Dockerfile that builds differently depending on the target architecture, you could resolve arch name on runtime, by checking the result of uname -m
and using shell conditionals, for example:
RUN /bin/ash -c 'set -ex && \
ARCH=`uname -m` && \
if [ "$ARCH" == "x86_64" ]; then \
echo "x86_64" && \
apk add some-package; \
else \
echo "unknown arch" && \
apk add some-other-package; \
fi'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.