Getting exec format error in ECS with Fargate


I am getting exec /bin/sh: exec format error while trying to deploy a basic Hello World container as ECS service using Fargate. Following are the steps I followed:

  1. Build the docker image using docker desktop for Mac
  2. Created the ECR repository using AWS console
  3. Pushed the docker image to ECR
  4. Created a task definition in ECS with Fargate as lunch type
  5. Tried to deploy ECS task as service

Here is the docker file I used to build the image:

FROM ubuntu:18.04

#Install dependencies

RUN apt-get update &&
apt-get -y install apache2

#Install apache and write hello world message

RUN echo 'Hello World!' > /var/www/html/index.html

#Configure apache

RUN echo '. /etc/apache2/envvars' > /root/ &&
echo 'mkdir -p /var/run/apache2' >> /root/ &&
echo 'mkdir -p /var/lock/apache2' >> /root/ && \ echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/ && \ chmod 755 /root/


While troubleshooting the error I have tried to put #!/bin/sh as the first line in the docker file but that also did not work. I have tried to change the image from apache to NGINX and used different docker file like below:

FROM nginx

RUN rm /etc/nginx/conf.d/*

COPY hello.conf /etc/nginx/conf.d/

COPY index.html /usr/share/nginx/html/

Using this image I am getting exec / exec format error

1 Answer

The "exec format error" error message usually indicates that the file you're trying to execute is not in the correct format. In this case, it could mean that the entrypoint script you're trying to run in the Docker image (/ is not in the correct format for the underlying system architecture. To resolve this issue, make sure the Docker image you're using is compatible with the system architecture of the Fargate cluster. If you're using a 64-bit Ubuntu 18.04 image, for example, the architecture should be x86_64. If the image is not compatible with the architecture, you'll need to create a new image that is compatible. In your second Dockerfile, it seems that you're missing the CMD command, which is required to run the container. You'll need to add the following line to the end of the Dockerfile to run Nginx:

CMD ["nginx", "-g", "daemon off;"]

This will run Nginx in the foreground, which is necessary for Fargate to manage the lifecycle of the container.

profile picture
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions