Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Docker Fails When Building on M1 Macs (exec /usr/local/bin/docker-entrypoint.sh: exec format error)

Ask Question

I got a legacy project running with docker-compose . A year ago it was starting with the configuration below.

Now it's throwing an error:

exec /usr/local/bin/docker-entrypoint.sh: exec format error

I would like to run the container with the CMD configuration. I found in the web to add #!/bin/bash is required to avoid this error, which I added to the Dockerfile.

There is no custom docker-entrypoint.sh defined. As far as I understand the docs there needs to be either an entrypoint or a command.

The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

Dockerfile

#!/bin/bash
#nodejs
FROM node:11.15
ENV NODE_VERSION 11.15
#app directory
WORKDIR ./
#mongodb tools
RUN wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add -
RUN echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
RUN apt-get update
RUN apt-get install -y mongodb
RUN apt-get install nano
#nodejs packages
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install --ignore-scripts sharp
RUN npm install --only=production
COPY . .
RUN mkdir -p /logs/
# wait for mongoDB launch
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.1/wait /wait
RUN chmod +x /wait
#port of the app
EXPOSE 8080
CMD /wait && npm run dockerServer

Docker Compose

version: "3"
services:
    watchtower:
        container_name: watchtower
        image: v2tec/watchtower
        env_file:
             - watchtower.env
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - /root/.docker/config.json:/config.json
        command: --interval 30
        restart: always
    mongo:
        container_name: mongo
        ports:
            - '27017:27017'
        volumes:
            - '/temp/im/docker/mongo/data:/data/db'
            - '/temp/im/docker/backup:/data/backup'
        image: mongo
        restart: always
    core:
        container_name: core
        ports:
            - '8080:8080'
        env_file:
            - core.env
        depends_on:
            - "mongo"
        volumes:
            - '/temp/im/docker/logs:/data/logs'
            - '/temp/im/docker/backup:/data/backup'
        image: index.docker.io/regname/core:beta
        logging:
            driver: "json-file"
            options:
                max-file: '5'
                max-size: '10m'
        restart: always

EDIT: I changed the title to make it better discoverable.

What CPU architecture is your host; are you on an M1 Mac? It looks like you're downloading and installing a Rust binary from a GitHub repository, does it have any shared-library dependencies you're missing? Can you docker-compose run core sh to get a debugging shell inside a new container and poke around (it is informative if you can't)? – David Maze Aug 18, 2022 at 10:37 (I'd suggest using CMD and not ENTRYPOINT here is preferable, in part because it makes that docker-compose run line straightforward. The "shebang" line won't make a difference here and is incorrect; it only would do something if you were trying to directly run ./Dockerfile as a command, and the Dockerfile isn't a shell script.) – David Maze Aug 18, 2022 at 10:39 Does this answer your question? Forcing docker to use linux/amd64 platform by default on macOS – Liam Mar 10 at 17:00 That did the trick. Googling it revealed it is a problem with Mac M1 chips and building docker images. stackoverflow.com/questions/65612411/… – Andi Giga Aug 18, 2022 at 12:17

Building on an M1 and deploying to Kubernetes gave me the same error:

exec /usr/local/bin/docker-entrypoint.sh: exec format error

The answer above fixed it for me as well:

FROM --platform=linux/amd64 node:18

Up and running.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.