Create your docker image for multi-architecture

Todsaporn Sangboon
3 min readJul 28, 2023

--

I have trouble with old public image andreysenov/firebase-tools to build Next.js application deploy to firebase hosting and DiscordHooks/gitlab-ci-discord-webhook. It doesn’t work Because It doesn’t have some packages like curl, git, libpng, nasm, etc. How can I do that? Yeah, the answer is to build your image for use.

The new docker image will support more than the old image below.

  • Support Next.js
  • Support gitlab-ci-discord-webhook

Below is the final Dockerfile for building the new Docker image

#original https://github.com/AndreySenov/firebase-tools-docker/blob/main/Dockerfile.node16
FROM node:16-alpine
ARG BUILD_DATE
ARG VERSION
ARG VCS_REF
LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="firebase-tools" \
org.label-schema.version=${VERSION} \
org.label-schema.build-date=${BUILD_DATE} \
org.label-schema.description="Firebase CLI on the NodeJS image" \
org.label-schema.url="https://github.com/firebase/firebase-tools/" \
org.label-schema.vcs-url="https://github.com/AndreySenov/firebase-tools-docker/" \
org.label-schema.vcs-ref=${VCS_REF}
ENV FIREBASE_TOOLS_VERSION=${VERSION}
ENV HOME=/home/node
EXPOSE 4000
EXPOSE 5000
EXPOSE 5001
EXPOSE 8080
EXPOSE 8085
EXPOSE 9000
EXPOSE 9005
EXPOSE 9099
EXPOSE 9199
RUN apk --no-cache add autoconf automake bash g++ libtool make openjdk11-jre python3 libpng-dev libpng nasm dpkg pkgconfig curl git && \
yarn global add firebase-tools@${VERSION} typescript && \
yarn cache clean && \
firebase setup:emulators:database && \
firebase setup:emulators:firestore && \
firebase setup:emulators:pubsub && \
firebase setup:emulators:storage && \
firebase -V && \
java -version && \
chown -R node:node $HOME
USER node
VOLUME $HOME/.cache
WORKDIR $HOME
CMD ["sh"]

Next, I’m trying to build using normal docker cmd. Yes, it works properly.

docker build -t nolifelover/firebase-tools:latest-node-16 .
docker push nolifelover/firebase-tools:latest-node-16 .

But when I’m using gitlab-ci.yml to build the Next.js project is not working because I’m using a Mac. The architecture of my computer is not compatible with my gitlab-runner, which is running on the amd64 architecture. How can I do that? Yeah, I am trying with the familiar way, “It is easy to solve that issue” I think.

docker build --platform linux/amd6 nolifelover/firebase-tools:latest-node-16 .
docker push nolifelover/firebase-tools:latest-node-16 .

It doesn’t because the docker build has not found manifest from node:16-alpine. I’m searching for a solution and found it by using ‘docker buildx’

What is Buildx?

Buildx is a Docker CLI plugin that extends the docker build command with the full support of the features provided by Moby BuildKit builder toolkit. It provides the same user experience as docker build with many new features like creating scoped builder instances and building against multiple nodes concurrently. Read more at GitHub.

Buildx plugin already installs with docker version > 19.03 or newer. Let’s set up and build again.

buildx create --use #firstime using buildx
buildx inspect #inspect buildx supported
#using buildx to build multi-architect and push to docker hub
docker buildx build --push --platform linux/amd64,linux/arm64 -t nolifelover/firebase-tools:latest-node-16 -f Dockerfile.node16 .

It works. You can use that image to build Next.js and support Gitlab discord notifications.

--

--

Todsaporn Sangboon

I'm developer and interest new programming technics - Ruby on Rails - Groovy on Grails - Codigniter