title: Can't connect to postgres when using docker-compose
body: <p>I am new to docker and still learning how to use it,
  I am trying to use docker-compose to run Django and Postgres together
  and they run perfectly and the migrate done and everything, but i have a problem i cant connect into the database using pgAdmin4 to look at the database
  that's my setting.py</p>
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'NAME': 'slack',
          'USER': 'username',
          'PASSWORD': 'password',
          'HOST': 'db',
          'PORT': 5432,
      }
  }
  </code></pre>
  <p>and that's my docker-compose.yml</p>
  <pre><code>version: '3'
  
  services:
    db:
      image: postgres
      environment:
          POSTGRES_DB: slack
          POSTGRES_USER: username
          POSTGRES_PASSWORD: password
    web:
      build: .
      command: python3 manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/slack_code
      ports:
        - &quot;8000:8000&quot;
      depends_on:
        - db
  </code></pre>
  <p>everything works seems to be fine :</p>
  <pre><code>sudo docker-compose up
  slackwebapp_db_1 is up-to-date
  Creating slackwebapp_web_1 ... done
  Attaching to slackwebapp_db_1, slackwebapp_web_1
  db_1   | The files belonging to this database system will be owned by user &quot;postgres&quot;.
  db_1   | This user must also own the server process.
  db_1   | 
  db_1   | The database cluster will be initialized with locale &quot;en_US.utf8&quot;.
  db_1   | The default database encoding has accordingly been set to &quot;UTF8&quot;.
  db_1   | The default text search configuration will be set to &quot;english&quot;.
  db_1   | 
  db_1   | Data page checksums are disabled.
  db_1   | 
  db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
  db_1   | creating subdirectories ... ok
  db_1   | selecting default max_connections ... 100
  db_1   | selecting default shared_buffers ... 128MB
  db_1   | selecting dynamic shared memory implementation ... posix
  db_1   | creating configuration files ... ok
  db_1   | running bootstrap script ... ok
  db_1   | performing post-bootstrap initialization ... ok
  db_1   | syncing data to disk ... ok
  db_1   | 
  db_1   | Success. You can now start the database server using:
  db_1   | 
  db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
  db_1   | 
  db_1   | 
  db_1   | WARNING: enabling &quot;trust&quot; authentication for local connections
  db_1   | You can change this by editing pg_hba.conf or using the option -A, or
  db_1   | --auth-local and --auth-host, the next time you run initdb.
  db_1   | waiting for server to start....2018-01-18 19:46:43.851 UTC [38] LOG:  listening on IPv4 address &quot;127.0.0.1&quot;, port 5432
  db_1   | 2018-01-18 19:46:43.851 UTC [38] LOG:  could not bind IPv6 address &quot;::1&quot;: Cannot assign requested address
  db_1   | 2018-01-18 19:46:43.851 UTC [38] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
  db_1   | 2018-01-18 19:46:43.853 UTC [38] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  db_1   | 2018-01-18 19:46:43.864 UTC [39] LOG:  database system was shut down at 2018-01-18 19:46:43 UTC
  db_1   | 2018-01-18 19:46:43.867 UTC [38] LOG:  database system is ready to accept connections
  db_1   |  done
  db_1   | server started
  db_1   | CREATE DATABASE
  db_1   | 
  db_1   | CREATE ROLE
  db_1   | 
  db_1   | 
  db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
  db_1   | 
  db_1   | 2018-01-18 19:46:44.388 UTC [38] LOG:  received fast shutdown request
  db_1   | waiting for server to shut down....2018-01-18 19:46:44.389 UTC [38] LOG:  aborting any active transactions
  db_1   | 2018-01-18 19:46:44.390 UTC [38] LOG:  worker process: logical replication launcher (PID 45) exited with exit code 1
  db_1   | 2018-01-18 19:46:44.391 UTC [40] LOG:  shutting down
  db_1   | 2018-01-18 19:46:44.402 UTC [38] LOG:  database system is shut down
  db_1   |  done
  db_1   | server stopped
  db_1   | 
  db_1   | PostgreSQL init process complete; ready for start up.
  db_1   | 
  db_1   | 2018-01-18 19:46:44.501 UTC [1] LOG:  listening on IPv4 address &quot;0.0.0.0&quot;, port 5432
  db_1   | 2018-01-18 19:46:44.501 UTC [1] LOG:  listening on IPv6 address &quot;::&quot;, port 5432
  db_1   | 2018-01-18 19:46:44.502 UTC [1] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  db_1   | 2018-01-18 19:46:44.514 UTC [65] LOG:  database system was shut down at 2018-01-18 19:46:44 UTC
  db_1   | 2018-01-18 19:46:44.518 UTC [1] LOG:  database system is ready to accept connections
  web_1  | Performing system checks...
  web_1  | 
  web_1  | System check identified no issues (0 silenced).
  web_1  | 
  web_1  | You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
  web_1  | Run 'python manage.py migrate' to apply them.
  web_1  | January 18, 2018 - 19:48:49
  web_1  | Django version 2.0.1, using settings 'slack_webapp.settings'
  web_1  | Starting development server at http://0.0.0.0:8000/
  web_1  | Quit the server with CONTROL-C.
  web_1  | [18/Jan/2018 19:56:03] &quot;GET / HTTP/1.1&quot; 200 16559
  web_1  | [18/Jan/2018 19:56:03] &quot;GET /static/admin/css/fonts.css HTTP/1.1&quot; 200 423
  web_1  | [18/Jan/2018 19:56:04] &quot;GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1&quot; 200 82564
  web_1  | [18/Jan/2018 19:56:04] &quot;GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1&quot; 200 80304
  web_1  | [18/Jan/2018 19:56:04] &quot;GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1&quot; 200 81348
  web_1  | [18/Jan/2018 19:56:08] &quot;GET /admin/ HTTP/1.1&quot; 302 0
  web_1  | [18/Jan/2018 19:56:09] &quot;GET /admin/login/?next=/admin/ HTTP/1.1&quot; 200 1855
  web_1  | [18/Jan/2018 19:56:09] &quot;GET /static/admin/css/base.css HTTP/1.1&quot; 200 16106
  web_1  | [18/Jan/2018 19:56:09] &quot;GET /static/admin/css/responsive.css HTTP/1.1&quot; 200 17894
  web_1  | [18/Jan/2018 19:56:09] &quot;GET /static/admin/css/login.css HTTP/1.1&quot; 200 1203
  web_1  | [18/Jan/2018 19:58:58] &quot;POST /admin/login/?next=/admin/ HTTP/1.1&quot; 302 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /admin/ HTTP/1.1&quot; 200 2988
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/css/base.css HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/css/dashboard.css HTTP/1.1&quot; 200 412
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/css/responsive.css HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/css/fonts.css HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1&quot; 304 0
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/img/icon-addlink.svg HTTP/1.1&quot; 200 331
  web_1  | [18/Jan/2018 19:58:58] &quot;GET /static/admin/img/icon-changelink.svg HTTP/1.1&quot; 200 380
  web_1  | [18/Jan/2018 19:59:05] &quot;GET /admin/ HTTP/1.1&quot; 200 2988
  web_1  | [18/Jan/2018 19:59:07] &quot;GET /admin/ HTTP/1.1&quot; 200 2988
  web_1  | [18/Jan/2018 19:59:11] &quot;GET /admin/ HTTP/1.1&quot; 200 2988
  ^CGracefully stopping... (press Ctrl+C again to force)
  Stopping slackwebapp_web_1 ... done
  Stopping slackwebapp_db_1  ... done
  </code></pre>
  <p>but still i cant connect and i don't know how to set up a password for the Postgres default user like we do in</p>
  <pre><code>sudo docker run --name test -e POSTGRES_PASSWORD=password -d postgres
  </code></pre>
  <p>cuz i cant do the same with docker-compose i guess, Thanks in advance.</p>