I have an EC2 linux2 instance containing dokcer compose. I want the instance to start the docker service, navigate to the correct folder, and then run docker-compose up -d, three simple lines, every time the instance start:
sudo service docker start
cd APP
docker-compose up -d
As shown here, entering this to the user data when the instance is stopped should work:
#!/bin/bash
sudo service docker start
cd APP
docker-compose up -d
But it does nothing. The aws doc has also this script:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
/bin/echo "Hello World" >> /tmp/testfile.txt <<<<<<<<------- ACTUAL USER SCRIPT
--//
When I paste my three lines instead of the hello world line, only the first one, start the docker service, works.
I am new to Linux, so it is probably something small that I'm missing.
Thanks
EDIT Thanks guys for your help, the issue is really the path to dir APP.