title: run docker-compose in EC2 user-data
body: <p>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:</p>
  <pre><code>sudo service docker start
  cd APP
  docker-compose up -d
  </code></pre>
  <p>As shown <a href="https://stackoverflow.com/questions/9764145/amazon-ec2-user-data-how-does-it-work">here</a>, entering this to the user data when the instance is stopped should work:</p>
  <pre><code>#!/bin/bash
  sudo service docker start
  cd APP
  docker-compose up -d
  </code></pre>
  <p>But it does nothing. The <a href="https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/" rel="nofollow noreferrer">aws doc</a> has also this script:</p>
  <pre><code>Content-Type: multipart/mixed; boundary=&quot;//&quot;
  MIME-Version: 1.0
  
  --//
  Content-Type: text/cloud-config; charset=&quot;us-ascii&quot;
  MIME-Version: 1.0
  Content-Transfer-Encoding: 7bit
  Content-Disposition: attachment; filename=&quot;cloud-config.txt&quot;
  
  #cloud-config
  cloud_final_modules:
  - [scripts-user, always]
  
  --//
  Content-Type: text/x-shellscript; charset=&quot;us-ascii&quot;
  MIME-Version: 1.0
  Content-Transfer-Encoding: 7bit
  Content-Disposition: attachment; filename=&quot;userdata.txt&quot;
  
  #!/bin/bash
  /bin/echo &quot;Hello World&quot; &gt;&gt; /tmp/testfile.txt  &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;------- ACTUAL USER SCRIPT
  --//
  </code></pre>
  <p>When I paste my three lines instead of the hello world line, only the first one, start the docker service, works.</p>
  <p>I am new to Linux, so it is probably something small that I'm missing.</p>
  <p>Thanks</p>
  <p>EDIT
  Thanks guys for your help, the issue is really the path to dir APP.</p>