4

I've single docker container and have to deploy on AWS Cloud using AWS ECR with Elastic Beanstalk. I'm using Dockerrun.aws.json file to provide the information about repository details. I have pushed my image to my docker hub and Elastic Container Registry.

Using DockerHub in ECS, It can pull the docker image from docker hub and starts the container without any issues and working the app as expected. On the other hand, the container gets stopped when the image pulled from AWS ECR Repository for the same application. The deployment gets failed for the reason: Essential container in task exited

Dockerrun.aws.json

{
    
    "containerDefinitions": [
        {
            "essential": true,
            "image": "01234567891.dkr.ecr.us-east-1.amazonaws.com/app:1",
            "memory": 512,
            "name": "web",
            "portMappings": [
                {
                    "containerPort": 5000,
                    "hostPort": 80
                }
            ]
        }
    ],
    "family": "",
    "volumes": [],
    "AWSEBDockerrunVersion": "2"
}

I logged into the instance and tried to get the logs of the containers. But, I got this error standard_init_linux.go:211: exec user process caused "exec format error"

Dockerfile

FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Walery Strauch
  • 6,792
  • 8
  • 50
  • 57
Kumaresh Babu N S
  • 1,648
  • 5
  • 23
  • 39
  • 2
    You've given no details on what you're doing, so it's pretty much impossible to give you any advice. Please provide a [mcve] and more than just an error message. – David Maze Jul 10 '20 at 14:23
  • Could it be a permissions issue, the container never gets downloaded from ECR? You could try another docker image to rule this out. – peter n Jul 10 '20 at 14:26
  • @petern I've tried with different image tag which never exists and it shows `CannotPullContainerError` but with the existing image tag, the error is different. – Kumaresh Babu N S Jul 10 '20 at 14:28
  • 1
    Please check your CloudWatch logs. If you're getting `Essential container in task exited`, there should be something in logs describing the reason, why. For the `exec format error`, see https://stackoverflow.com/questions/36544293/docker-run-9-system-error-exec-format-error. Seems like there's an error in your `Dockerfile`. – lexicore Jul 10 '20 at 18:13
  • 1
    You might want to post your `Dockerfile`. – lexicore Jul 10 '20 at 18:13
  • @lexicore I've updated the question with the dockerfile. – Kumaresh Babu N S Jul 11 '20 at 06:06
  • @KumareshBabuNS switch out the image you are using for something else like a Grafana or so. If it works you know that the problem is within your Python code – trallnag Jul 11 '20 at 14:02

2 Answers2

2

Seems like there is depended on docker container in task definition or the docker-compose file.

This error occur you have container B that is opened on A and A is esetional for services, so container B will automatically exit.

You need to debug why A is exit.

Essential container in task exited

If a container marked as essential in task definitions exits or dies, that can cause a task to stop. When an essential container exiting is the cause of a stopped task, the Step 6 can provide more diagnostic information as to why the container stopped.

stopped-task-errors

Adiii
  • 54,482
  • 7
  • 145
  • 148
2

The problem lies in AWS CodeBuild Project. I've mistakenly provided the wrong architecture for the build. The docker image built on different architecture and tried to run on the different architecture in the deployment state. I've changed to the same architecture which is used for the deployment. Both the docker hub image and ECR image seems working fine.

Kumaresh Babu N S
  • 1,648
  • 5
  • 23
  • 39
  • I got here because I was building Docker images on my M1 Mac and was pushing them to ECR. Oops! – a paid nerd Apr 09 '21 at 20:00
  • If you're building them on your M1 do they automatically inherit the wrong architecture? If so, what's the way around this? @apaidnerd did you find a workaround? – Dan Engel Mar 16 '22 at 03:29