40

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.

Andi Giga
  • 3,744
  • 9
  • 38
  • 68
  • 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 '22 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 '22 at 10:39
  • Does this answer your question? [Forcing docker to use linux/amd64 platform by default on macOS](https://stackoverflow.com/questions/65612411/forcing-docker-to-use-linux-amd64-platform-by-default-on-macos) – Liam Mar 10 '23 at 17:00

3 Answers3

86

Try to change FROM:

FROM --platform=linux/amd64 node:11.15

There is a good explanation.

plplmax
  • 1,765
  • 8
  • 19
  • 2
    That did the trick. Googling it revealed it is a problem with Mac M1 chips and building docker images. https://stackoverflow.com/questions/65612411/forcing-docker-to-use-linux-amd64-platform-by-default-on-macos – Andi Giga Aug 18 '22 at 12:17
  • This helped me fix a crash loop failure on my K8s cluster as well. Thank you! – Kevin Ghaboosi Feb 09 '23 at 04:41
4

Building docker image with the following also works. docker build --platform=linux/amd64 -t <image:tag>

Ramya Musunuru
  • 177
  • 1
  • 5
3

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.