title: docker-compose: console does not return to host when creating database container
body: <p>I'm trying to create a postgresql docker container using docker-compose, but it seems that when I use a pre-ready postgresql image the console never return to the host, and if I hit Ctrl+C the container ends up being stoped. Here is what I got:</p>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '2'
  services:
    database:
      container_name: database_server
      build:
        context: .
        dockerfile: Dockerfile_database
      image: database:tag
      expose:
        - "5432"
  </code></pre>
  
  <p><strong>Dockerfile_database</strong></p>
  
  <pre><code>FROM library/postgres
  ADD init.sql /docker-entrypoint-initdb.d/
  </code></pre>
  
  <p><strong>init.sql</strong></p>
  
  <pre><code>CREATE USER usuario WITH PASSWORD 'senha';
  CREATE DATABASE telesaude;
  GRANT ALL PRIVILEGES ON DATABASE telesaude TO usuario;
  </code></pre>
  
  <p>and during the container creation the console shows some postgresql logs, such as this:</p>
  
  <pre><code>Building database
  Step 1/2 : FROM library/postgres
   ---&gt; 4023a747a01a
  Step 2/2 : ADD init.sql /docker-entrypoint-initdb.d/
   ---&gt; e264774d1f0b
  Removing intermediate container 8df766b5a9f2
  Successfully built e264774d1f0b
  WARNING: Image for service database was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
  Creating database_server
  Attaching to database_server
  database_server | The files belonging to this database system will be owned by user "postgres".
  database_server | This user must also own the server process.
  database_server | 
  database_server | The database cluster will be initialized with locale "en_US.utf8".
  database_server | The default database encoding has accordingly been set to "UTF8".
  database_server | The default text search configuration will be set to "english".
  database_server | 
  database_server | Data page checksums are disabled.
  database_server | 
  database_server | fixing permissions on existing directory /var/lib/postgresql/data ... ok
  database_server | creating subdirectories ... ok
  database_server | selecting default max_connections ... 100
  database_server | selecting default shared_buffers ... 128MB
  database_server | selecting dynamic shared memory implementation ... posix
  database_server | creating configuration files ... ok
  database_server | running bootstrap script ... ok
  database_server | performing post-bootstrap initialization ... ok
  database_server | syncing data to disk ... 
  database_server | WARNING: enabling "trust" authentication for local connections
  database_server | You can change this by editing pg_hba.conf or using the option -A, or
  database_server | --auth-local and --auth-host, the next time you run initdb.
  database_server | ok
  database_server | 
  database_server | Success. You can now start the database server using:
  database_server | 
  database_server |     pg_ctl -D /var/lib/postgresql/data -l logfile start
  database_server | 
  database_server | ****************************************************
  database_server | WARNING: No password has been set for the database.
  database_server |          This will allow anyone with access to the
  database_server |          Postgres port to access your database. In
  database_server |          Docker's default configuration, this is
  database_server |          effectively any other container on the same
  database_server |          system.
  database_server | 
  database_server |          Use "-e POSTGRES_PASSWORD=password" to set
  database_server |          it in "docker run".
  database_server | ****************************************************
  database_server | waiting for server to start....LOG:  database system was shut down at 2017-02-02 21:15:46 UTC
  database_server | LOG:  MultiXact member wraparound protections are now enabled
  database_server | LOG:  database system is ready to accept connections
  database_server | LOG:  autovacuum launcher started
  database_server |  done
  database_server | server started
  database_server | ALTER ROLE
  database_server | 
  database_server | 
  database_server | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
  database_server | CREATE ROLE
  database_server | CREATE DATABASE
  database_server | GRANT
  database_server | 
  database_server | 
  database_server | LOG:  received fast shutdown request
  database_server | LOG:  aborting any active transactions
  database_server | waiting for server to shut down...LOG:  autovacuum launcher shutting down
  database_server | .LOG:  shutting down
  database_server | LOG:  database system is shut down
  database_server |  done
  database_server | server stopped
  database_server | 
  database_server | PostgreSQL init process complete; ready for start up.
  database_server | 
  database_server | LOG:  database system was shut down at 2017-02-02 21:15:49 UTC
  database_server | LOG:  MultiXact member wraparound protections are now enabled
  database_server | LOG:  database system is ready to accept connections
  database_server | LOG:  autovacuum launcher started
  (console never returns to host after this)
  </code></pre>
  
  <p>What should I do so the container keeps running/started and the console returns to host? <strong>I have to use docker-compose.</strong> Can't use docker run -d ... </p>