skip to Main Content
Part of my dockerfile:

FROM node:18-alpine as installer
WORKDIR /app
ENV NODE_ENV=development
COPY package*.json .
COPY tsconfig.json .
RUN npm ci

FROM node:18-alpine as builder
WORKDIR /app
ENV NODE_ENV=development
COPY --from=installer /app/ .
COPY src/ ./src/
RUN npm run build

Part of my docker-compose.yml

version: '3.8'

services:
  function-app:
    container_name: function-app
    restart: always
    depends_on:
      - mongo
    build: .
    environment:
      - DB_HOST=mongo:27017
      - DB_USERNAME=qq
      - DB_PASSWORD=qq
    ports:
      - 1337:80
    volumes:
      - ./dist/:/home/site/wwwroot/

This works for all my colleagues.

I’m getting this:

enter image description here

I tried changing to FROM --platform=linux/amd64 node:18-alpine as installer

No effect.

I’m the only one on the team running an Apple M1 computer. Maybe thats the problem?

Any suggestions what might be the problem and how to solve it?

Update

I reinstalled docker.
Got a new error: "Function not implemented"
Which pointed me here: https://github.com/Azure/azure-functions-core-tools/issues/2901

Summary of that thread: There currently is no solution for M1.

So we moved away from docker on the project (not the most popular team member at the moment).

Thanks for all answers!

3

Answers


  1. What output has docker info command? Maybe you should install docker via brew: brew install --cask docker

    Login or Signup to reply.
  2. In my original answer, posted below, I tried to help you create a node image capable of running for Apple M1 arm64 architecture, but the reason of the problem could be another.

    You included the installer and builder images you are using in your Docker file but, according to the error you provided, you seem to be using the Azure Functions for node docker image.

    If that is the case, it seems that, at the moment, as you can see in this or this other Github issues, this image doesn’t support the arm64 architecture yet. You can verify it as well reviewing the list of the different tags in Docker Hub.

    You can try building your own images as suggested in this post, but I don’t know if it is a possible solution.

    I think there shouldn’t be any problem in building your image for amd64 using Apple M1 and the approach suggested in my previous answer below or a similar one; the result image should be able to be run in linux amd64 without further problem. The only problem is try running it in arm64.

    To provide context, my original answer follows.

    My first words should be that I don’t have the opportunity to use an Apple M1 computer, so the following answer is based only on assumptions and not on facts as I would like: please, take that only as general guidance, background information, and not as a true answer, because I am unsure if it would work.

    The error indicates that your Functions runtime could be started appropriately.

    It could be motivated by different things and the use of an unsupported version of node due to the use of the different chipset architecture of Apple Silicon M1 could be one of them.

    It may have no effect, but you could try building explicitly your image for a different architecture.

    The process of building multi-platform images is very well described in the Docker documentation.

    That documentation provides a getting started section that indicates the different steps that need to be carried out in order to setup the build system.

    Basically, as a first step, you probably will need to create a new builder based on the docker container driver:

    docker buildx create --name my-builder --driver docker-container --use
    

    As stated in the docs:

    Using the docker-container driver has a couple of advantages over the basic
    docker driver. Firstly, we can manually override the version of buildkit to
    use, meaning that we can access the latest and greatest features as soon as
    they’re released, instead of waiting to upgrade to a newer version of
    Docker. Additionally, we can access more complex features like multi-
    architecture builds and the more advanced cache exporters, which are
    currently unsupported in the default docker driver.

    The created builder should appear in the list of available ones. You can verify it issuing the following command:

    docker buildx ls
    

    As explained in the aforementioned Docker documentation, depending on your setup, it may be necessary to install the following for providing support for additional platforms:

    docker run --privileged --rm tonistiigi/binfmt --install all
    

    Please, consider read this related SO question.

    If everything is fine, you should be able to build your image with something like the following from the directory:

    docker buildx build --platform linux/arm64 -t your_image --load .
    

    The above command assumes you are not using a registry and that the image will be stored locally: it will work only if you provide a single platform destination.

    Please, note I used linux/arm64 and not linux/amd64: honestly I am a bit confused about that, but I think you should use the platform in which your application should be run into. This great article from the docker blog, in general, provides one of the better explanations I have ever read about how docker multi-platform builds work; particularly, it provides great guidance about the different variables you could use to make your Dockerfile portable across different platforms.

    The generated image could be used later in docker-compose:

    version: '3.8'
    
    services:
      function-app:
        container_name: function-app
        restart: always
        depends_on:
          - mongo
        image: your_image
        environment:
          - DB_HOST=mongo:27017
          - DB_USERNAME=qq
          - DB_PASSWORD=qq
        ports:
          - 1337:80
        volumes:
          - ./dist/:/home/site/wwwroot/
    

    I was digging into the issue when I saw your question and it "seems" that docker-compose is unable to build the image as described: that is the reason why I used the docker buildx command directly. Please, consider review this SO question and the following Docker Desktop documentation regarding this issue.

    Login or Signup to reply.
  3. To solve this problem, You can try change the Dockerfile to:

    FROM --platform=linux/amd64 node:18-alpine as installer
    WORKDIR /app
    ENV NODE_ENV=development
    COPY package*.json .
    COPY tsconfig.json .
    RUN npm ci
    
    FROM --platform=linux/amd64 node:18-alpine as builder
    WORKDIR /app
    ENV NODE_ENV=development
    COPY --from=installer /app/ .
    COPY src/ ./src/
    RUN npm run build
    
    FROM --platform=linux/amd64 node:18-alpine as runner
    WORKDIR /app
    ENV NODE_ENV=production
    COPY --from=builder /app/ .
    COPY --from=builder /app/node_modules/ ./node_modules/
    EXPOSE 80
    CMD ["npm", "start"]
    

    Explanation: The problem was that the node:18-alpine image is not available for the Apple M1 architecture. The solution was to use the –platform=linux/amd64 flag to force the image to be built for the x86 architecture.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search