Search code examples
node.jslinuxdockeramazon-ecsyarnpkg

How to solve Docker container exec format error for running entrypoint


Perviously the question was related to Yarn command not found after successful docker build. But it was fixed but my problem is related to using shell /bin/sh Here's What I am trying to do use yarn and install it on amazonlinux:2 image Here's my Dockerfile

FROM amazonlinux:2

RUN yum update -y && \
    yum install -y tar curl gzip zip unzip aws-cli

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | sh && \
    . ~/.nvm/nvm.sh && \
    nvm install 14 && \
    nvm alias default 14 && \
    nvm use default && \
    npm install -g yarn

USER root

COPY .bashrc /root/.bashrc

COPY entrypoint.sh /root/entrypoint.sh

RUN chmod +x /root/entrypoint.sh

ENTRYPOINT [ "/root/entrypoint.sh" ]

And this is my .bashrc file

#!/bin/sh
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

ANd this is my entrypoint.sh

#!/bin/sh
. /root/.bashrc
exec "$@"

All I get is while trying to run container from ECS exec /root/entrypoint.sh: exec format error and Essential container in task exited How to solve the exec format error?Please help me


Solution

  • The exec format error message means that you have built your docker image on an ARM system like a Mac M1, and are trying to run it on an X86 system, or the opposite, building it on an X86 computer and trying to run it on an ARM system like an AWS Graviton environment.

    You either need to use Docker BuildKit to build the image for the environment you intend to run it, or make sure that your build environment and deployment environment have the same CPU architecture.