Search code examples
amazon-web-servicesamazon-ecsaws-fargateecs-taskdefinition

How to put multiline commands in ECS Task definition


I am trying to run a django application inside of a docker container (ECS - Fargate)

However, I am having trouble figuring out how to run multiple commands in the Command section of a task definition, currently it is configured like this

enter image description here

Howevery my containers keep on STOPPING and I cant even see the logs in CloudWatch

enter image description here

How do I get it to execute properly?, any help is highly appreciated


Solution

  • In your case I would do this by using /bin/sh -c despite the entry point:

    /bin/sh -c "python manage.py ... <and the rest>"
    

    This is also how it is done in the offical AWS ECS tutorial:

                "entryPoint": [
                    "sh",
                    "-c"
                ],
                "command": [
                    "/bin/sh -c \"echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' >  /usr/local/apache2/htdocs/index.html && httpd-foreground\""
                ]