skip to Main Content

I haven’t used buildx much and can’t figure out what is going on here. When I run a buildx build on my intel Mac, everything builds fine for arm64, but when I have a GitLab runner do the build on an amd64 server, it fails with.

[builder 4/6] RUN which node
0.514 /usr/local/bin/node
 DONE 0.6s

[builder 5/6] RUN node -v
0.633 v16.13.0
 DONE 0.7s

[builder 6/6] RUN npm install
0.360 Error while loading /usr/local/sbin/node: No such file or directory

I seen npm is looking in the wrong place, but why is it looking for /usr/local/sbin/node on the GitLab runner but in the correct path on my Mac? This Dockerfile builds fine if I just run.

$ docker build .

Local command:

$ docker buildx create --use
$ docker buildx build --platform linux/arm64 .

GitLab Runner buildx environment

$ docker buildx create --platform linux/amd64,linux/arm64 --use
epic_wright

$ docker buildx ls
NAME/NODE      DRIVER/ENDPOINT      STATUS   PLATFORMS
epic_wright *  docker-container              
  epic_wright0 tcp://localhost:2375 inactive linux/amd64*, linux/arm64*
default        docker                        
  default      default              running  linux/amd64, linux/386

Dockerfile

FROM node:16.13.0-bullseye

ARG GITLAB_AUTH_TOKEN

COPY ./app /app
WORKDIR /app

RUN which node
RUN node -v
RUN npm install

.gitlab-ci.yml

image: eventngine/docker-buildx

stages:
  - build

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: tcp://localhost:2375

build:
  stage: build
  services:
    - name: docker:19.03.12-dind
      command: ["--experimental"]
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker buildx create --use
    - docker buildx build -t "$CI_REGISTRY_IMAGE:v${CI_COMMIT_SHA:0:8}" --build-arg GITLAB_AUTH_TOKEN=$CI_JOB_TOKEN  --platform linux/arm64 --push .
  only:
    - main

Would appreciate any ideas, thanks so much!

3

Answers


  1. When running into a similar issue running npm install during a buildx build, I was was able to resolve with

    docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

    After that, my npm install ran great for all the architectures I was attempting to build for.

    Login or Signup to reply.
  2. For me this was some issue with my cached images. I’d cleared the docker cache but something went wrong with the buildx cache. Running,

    docker buildx prune

    resolved it for me.

    Login or Signup to reply.
  3. I found this issue on Docker buildx repository where they explain why this is happening and how can you solve it.
    They also provide examples for Github Actions and other solutions for different use cases.

    Basically, you need to add these three lines before the docker buildx build command in your .gitlab-ci.yml file:

    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker buildx create --driver docker-container --use
    - docker buildx inspect --bootstrap
    

    In this case, the file should look like this:

    build:
      stage: build
      services:
        - name: docker:19.03.12-dind
          command: ["--experimental"]
      script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
        - docker buildx create --driver docker-container --use
        - docker buildx inspect --bootstrap
        - docker buildx build -t "$CI_REGISTRY_IMAGE:v${CI_COMMIT_SHA:0:8}" --build-arg GITLAB_AUTH_TOKEN=$CI_JOB_TOKEN  --platform linux/arm64 --push .
      only:
        - main
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search