title: Difference between docker-compose and manual commands
body: <h3>What I'm trying to do</h3>
  
  <p>I want to run a yesod web application in one docker container, linked to a postgres database in another docker container.</p>
  
  <h3>What I've tried</h3>
  
  <p>I have the following file hierarchy:</p>
  
  <pre><code>/
      api/
          Dockerfile
      database/
          Dockerfile
      docker-compose.yml
  </code></pre>
  
  <p>The <code>docker-compose.yml</code> looks like this:</p>
  
  <pre><code>database:
      build: database
  api:
      build: api
      command: .cabal/bin/yesod devel # dev setting
      environment:
          - HOST=0.0.0.0
          - PGHOST=database
          - PGPORT=5432
          - PGUSER=postgres
          - PGPASS
          - PGDATABASE=postgres
      links:
          - database
      volumes:
          - api:/home/haskell/
      ports:
          - "3000:3000"
  </code></pre>
  
  <p>Running <code>sudo docker-compose up</code> fails either to start the api container at all or, just as often, with the following error:</p>
  
  <pre><code>api_1      | Yesod devel server. Press ENTER to quit
  api_1      | yesod: &lt;stdin&gt;: hGetLine: end of file
  personal_api_1 exited with code 1
  </code></pre>
  
  <p>If, however, I run <code>sudo docker-compose database up &amp;</code> then start up the api container without using compose but instead using</p>
  
  <pre><code>sudo docker run -p 3000:3000 -itv /home/me/projects/personal/api/:/home/haskell --link personal_database_1:database personal_api /bin/bash
  </code></pre>
  
  <p>I can <code>export</code> the environment variables being set up in the <code>docker-compose.yml</code> file then manually run <code>yesod devel</code> and visit my site successfully on localhost.</p>
  
  <p>Finally, I obtain a third different behaviour if I run <code>sudo docker-compose run api</code> on its own. This seems to start successfully but I can't access the page in my browser. By running <code>sudo docker-compose run api /bin/bash</code> I've been able to explore this container and I can confirm the environment variables being set in <code>docker-compose.yml</code> are all set correctly.</p>
  
  <h3>Desired behaviour</h3>
  
  <p>I would like to get the result I achieve from running the database in the background then manually setting the environment in the api container's shell simply by running <code>sudo docker-compose up</code>.</p>
  
  <h3>Question</h3>
  
  <p>Clearly the three different approaches I'm trying do slightly different things. But from my understanding of docker and docker-compose I would expect them to be essentially equivalent. Please could someone explain how and why they differ and, if possible, how I might achieve my desired result?</p>