amazon-web-servicesamazon-ec2bitbucket-pipelinesaws-code-deploybitbucket-aws-code-deploy

Why is my Docker container stuck in a state of "Created"?


I am trying to deploy to EC2 using Bitbucket Pipelines and AWS CodeDeploy. I have everything setup so that the upload step for the CodeDeploy Agent works as it should, it's just that when I try running the statement in the deploy step, my script.sh /usr/local/bin/docker-compose -f /home/ec2-user/my-app/docker-compose.yml run --rm composer install fails.

Everything else works and if I remove this step, it deploys successfully. If I try to execute this command manually it also works and the container for this runs and then exits as it should. I've checked permissions, changed my IAM setup and done everything I can think of before coming here.


Solution

  • So after a LONG time searching, running countless pipeline deployments and hammering my build minutes for weeks on end, I finally got to the bottom of the problem and am hoping this may help anyone with the same problem.

    It was a permissions issue that was failing to run execute commands such as docker-compose run. With AWS Code Deploy, we run the scripts for the life cycle hooks in appspec.yml, usually as root. However, the AWSCodeDeployRole needs full permissions - in my case this was for EC2 so was missing the AmazonEC2FullAccess policy that needs to be attached to the AWSCodeDeployRole. Also add ec2.amazonaws.com to the JSON trust policy, this is what worked for me...2 months later!