title: Where is the Postgres username/password being created in this Dockerfile?
body: <p>So I was following this tutorial:
  <a href="https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/" rel="noreferrer">https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/</a></p>
  
  <p>I have everything up and running, however theres a few things going on that I'm not able to follow or understand.</p>
  
  <p>In the main Docker-Compose we have:</p>
  
  <pre><code>web:
    restart: always
    build: ./web
    expose:
      - "8000"
    links:
      - postgres:postgres
      - redis:redis
    volumes:
      - /usr/src/app
      - /usr/src/app/static
    env_file: .env
    command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000
  
  postgres:
    restart: always
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data/
  </code></pre>
  
  <p>You will notice there is a env_file containing:</p>
  
  <pre><code>DB_NAME=postgres    
  DB_USER=postgres    
  DB_PASS=postgres
  </code></pre>
  
  <p>My question is when is the postgres user and password being set?  If I run this docker-compose everything works, meaning the web app can pass credentials to the postgress database and establish a connection.  I'm not able to follow however, where those credentials are being set in the first place.</p>
  
  <p>I was assuming in the base postgres Dockerfile, there would be some instruction to set the database name, username and password.  I do not it though.  Here is a copy of the base postgres Dockerfile below.</p>
  
  <pre><code># vim:set ft=dockerfile:
  
  FROM debian:jessie
  
  
  
  # explicitly set user/group IDs
  
  RUN groupadd -r postgres --gid=999 &amp;&amp; useradd -r -g postgres --uid=999 postgres
  
  
  
  # grab gosu for easy step-down from root
  
  ENV GOSU_VERSION 1.7
  
  RUN set -x \
  
      &amp;&amp; apt-get update &amp;&amp; apt-get install -y --no-install-recommends ca-certificates wget &amp;&amp; rm -rf /var/lib/apt/lists/* \
  
      &amp;&amp; wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
  
      &amp;&amp; wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
  
      &amp;&amp; export GNUPGHOME="$(mktemp -d)" \
  
      &amp;&amp; gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
  
      &amp;&amp; gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
  
      &amp;&amp; rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
  
      &amp;&amp; chmod +x /usr/local/bin/gosu \
  
      &amp;&amp; gosu nobody true \
  
      &amp;&amp; apt-get purge -y --auto-remove ca-certificates wget
  
  
  
  # make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
  
  RUN apt-get update &amp;&amp; apt-get install -y locales &amp;&amp; rm -rf /var/lib/apt/lists/* \
  
      &amp;&amp; localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
  
  ENV LANG en_US.utf8
  
  
  
  RUN mkdir /docker-entrypoint-initdb.d
  
  
  
  RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
  
  
  
  ENV PG_MAJOR 9.6
  
  ENV PG_VERSION 9.6.1-1.pgdg80+1
  
  
  
  RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR &gt; /etc/apt/sources.list.d/pgdg.list
  
  
  
  RUN apt-get update \
  
      &amp;&amp; apt-get install -y postgresql-common \
  
      &amp;&amp; sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
  
      &amp;&amp; apt-get install -y \
  
          postgresql-$PG_MAJOR=$PG_VERSION \
  
          postgresql-contrib-$PG_MAJOR=$PG_VERSION \
  
      &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  
  
  # make the sample config easier to munge (and "correct by default")
  
  RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
  
      &amp;&amp; ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
  
      &amp;&amp; sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
  
  
  
  RUN mkdir -p /var/run/postgresql &amp;&amp; chown -R postgres /var/run/postgresql
  
  
  
  ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
  
  ENV PGDATA /var/lib/postgresql/data
  
  VOLUME /var/lib/postgresql/data
  
  
  
  COPY docker-entrypoint.sh /
  
  
  
  ENTRYPOINT ["/docker-entrypoint.sh"]
  
  
  
  EXPOSE 5432
  
  CMD ["postgres"]
  </code></pre>