title: How to run docker-compose on AWS CodeBuild?
body: <p>I'm trying to setup automated Rails tests on AWS CodeBuild using docker-compose, but it errors out.</p>
  
  <p>In buildspec.yml:</p>
  
  <pre><code>phases:
    build:
      commands:
          - docker-compose up -d
  
  [Container] 2018/10/23 11:27:56 Running command docker-compose up -d
  Couldn't connect to Docker daemon at http+docker://localhost - is it running?
   If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
   [Container] 2018/10/23 11:27:56 Command did not exit successfully docker-compose up -d exit status 1
  [Container] 2018/10/23 11:27:56 Running command echo This always runs even if the install command fails
  This always runs even if the install command fails
   [Container] 2018/10/23 11:27:56 Phase complete: BUILD Success: false
  [Container] 2018/10/23 11:27:56 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker-compose up -d. Reason: exit status 1
  </code></pre>
  
  <p>Presumably I need to install docker and start the service, but that would be running Docker inside Docker and would require the build server to be started with privileged permission. Only examples I can see are for building Docker images, but I'm just trying to use it to setup the environment to run the test in.</p>
  
  <h1>ANSWERED: Set up Docker image in CodeBuild's Environment section</h1>
  
  <p>Thanks to @mferre for answering this. Docker-compose is indeed completely supported without doing anything special. The key is to choose a Docker image in the "environment" section when setting up inside AWS CodeBuild console (or same via the API):</p>
  
  <p><a href="https://i.stack.imgur.com/QzDpz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QzDpz.png" alt="enter image description here"></a></p>
  
  <p>Or can also be specified for an existing project - from Build / Build Projects, select the project, and Environments from the Edit menu. This lets you specify the image:</p>
  
  <p><a href="https://i.stack.imgur.com/uKnr0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uKnr0.png" alt="enter image description here"></a></p>
  
  <p>You could use any other image and script the Docker setup in <code>buildspec.yml</code>, but the easiest way is to use the official Docker image as above. With this as the container, docker and docker-compose are pre-installed, so docker-compose "just works". If the project has a <code>docker-compose.yml</code> file in its root, the <code>buildspec.yml</code> can be as simple as running it immediately:</p>
  
  <pre><code>version: 0.2
  phases:
    build:
      commands:
        - docker-compose up -d
  </code></pre>