Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'exec user process caused: exec format error' in AWS Fargate Service

I am totally new to AWS but I've been running my dockerized application locally for months now with no issues. Now that I am trying to deploy this app via AWS ECS/Fargate, my containers are stopped repeatedly with this linux error: standard_init_linux.go:219: exec user process caused: exec format error. This error seems to suggest that the architecture in Fargate does not recognize one of the Linux commands I'm running but I can't find a good answer anywhere for how to find the architecture that's running or how to track down the specific command that's causing the issue.

These are my Dockerfiles for the frontend and backend. The project is built in the MERN stack and is split into the frontend (React) and the backend (MongoDB/Express)

Frontend:

FROM alpine:3.10

ENV NODE_VERSION 15.9.0

WORKDIR /frontend

COPY package*.json ./

RUN apk add --no-cache nodejs npm

# some packages rely on gyp so we need this
# pulled from https://github.com/nodejs/docker-node/issues/282
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

Backend:

FROM alpine:3.10

ENV NODE_VERSION 15.9.0

WORKDIR /backend

COPY package*.json ./

RUN apk add --no-cache nodejs npm

# some packages rely on gyp so we need this
# pulled from https://github.com/nodejs/docker-node/issues/282
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install --silent\
    && apk del .gyp

COPY ./ ./

EXPOSE 8080

CMD ["npm", "start"]

Any help would be greatly appreciated!

like image 404
StephenKernan Avatar asked May 02 '21 23:05

StephenKernan


People also ask

What is ECS Exec in AWS Fargate?

Today, we are announcing the ability for all Amazon ECS users including developers and operators to “exec” into a container running inside a task deployed on either Amazon EC2 or AWS Fargate. This new functionality, dubbed ECS Exec, allows users to either run an interactive shell or a single command against a container.

Who is working on AWS Fargate?

He has been working on containers since 2014 and that is Massimo’s current area of focus within the compute service team at AWS . Massimo has a blog at www.it20.info and his Twitter handle is @mreferre. Saloni Sonpal Saloni is a Product Manager in the AWS Containers Services team. She focuses on all things AWS Fargate.

Can I apply ECS Exec to my own tasks and IAM?

If you are an experienced Amazon ECS user, you may apply the specific ECS Exec configurations below to your own existing tasks and IAM roles. If you are an AWS Copilot CLI user and are not interested in an AWS CLI walkthrough, please refer instead to theCopilot documentation.

What is exec format error in Docker?

Docker throws error standard_init_linux.go:228: exec user process caused: exec format error when there are issues with executable file format. It could happen due to these reasons – You forgot to put #!/bin/bash at the top of shell files. There is a space before shebang ( #!/bin/bash ). Using #!/bin/bash instead of #!/bin/ash for alpine images.


2 Answers

Short answer: docker buildx build --platform=linux/amd64 -t <image-name> .

like image 78
Ben Francom Avatar answered Oct 13 '22 01:10

Ben Francom


I think you've identified your problem.

You're building your images on Apple's M1 chip, which is an ARM architecture. Fargate is probably running on the more common Intel x86-64 architecture. Images you build locally on your Mac aren't going to be able to run there.

The easiest solution is probably to have your images build automatically in Docker Hub (or use a Github Action to build them in Github).

I don't have all the details about how you're building and deploying your images, so it's possible I'm missing some details.

like image 43
larsks Avatar answered Oct 13 '22 01:10

larsks