Search code examples
dockergithub-actionscpu-architecturebuildx

Getting docker-entrypoint.sh: exec format error while the architecture matches


I've the following Dockerfile

FROM --platform=$BUILDPLATFORM node:lts
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY index.js .
CMD ["node", "index.js"]

index.js is just console.log("Hello World");

I can build & run the image in my MacBook m3 (uname -m prints arm64)

Now, what I'm trying is to do is build the image in GitHub Actions and post it in Github Package Registry.

I've tried with this workflow:

name: Create and publish a Docker image

on:
  push:
    branches: ['release']

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}


jobs:
  build-and-push-image:
    runs-on: ubuntu-latest

    permissions:
      contents: read
      packages: write
      pages: write
      
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to the Container registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
 
      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      - name: Build and push Docker image
        id: push
        uses: docker/build-push-action@v5
        with:
          platforms: linux/arm64
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Which creates an image, but when I pull it and run it, I get a exec /usr/local/bin/docker-entrypoint.sh: exec format error. I had this error in the past and it normally indicates that the Core Image (the one from the initial FROM step) that was used to build the image isn't matching the arch where we're trying to run it.. but when I do docker inspect I can check that the architecture is arm64. When I check GitHub Action logs, the sha256 matches the multi-arch image index from node.

Not sure what I'm doing wrong, all my troubleshooting ideas are not reaching anything T_T.

  • I've tried to docker system prune -a before pulling the image. I can see that I'm pulling all the layers, it still fails while running it.
  • I've tried to use qemu before calling setup-buildx but I don't see any difference. I understand I do not need qeru for this (?)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3 

Edit: Setting

`FROM node@sha256:e256e6fb2dd3b003ea634a657f7da94bb34a98e599d7bcb99b5bec30a1343eae`

Makes it work, which makes it even more confusing for me, as this is the same sha256 that I was seeing in the previous GitHub Actions logs.


Solution

  • You have a broken image. The FROM line specifies --platform=$BUILDPLATFORM which means no matter the target platform for the image, the binaries included in the image layers will match the build platform architecture. You need to remove that from the Dockerfile to stop building images with a platform that doesn't match the contents of the filesystem layers.