title: could not translate host name "db" to address: Temporary failure in name resolution
body: <p>I am trying to build postgres with <code>django</code> from official docker documentation samples <a href="https://docs.docker.com/samples/django/" rel="nofollow noreferrer">link</a> nevertheless for unknown reason i am getting following error which i tried to solve without success. Please of help.</p>
  <p>This is output with error i got:</p>
  <pre><code>╰─ docker-compose up
  [+] Running 2/2
   ⠿ Container postgresdjango_db_1   Created                                                                                                                            0.0s
   ⠿ Container postgresdjango_web_1  Recreated                                                                                                                          2.5s
  Attaching to db_1, web_1
  db_1   | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
  db_1   | Error: Database is uninitialized and superuser password is not specified.
  db_1   |        You must specify POSTGRES_PASSWORD to a non-empty value for the
  db_1   |        superuser. For example, &quot;-e POSTGRES_PASSWORD=password&quot; on &quot;docker run&quot;.
  db_1   |
  db_1   |        You may also use &quot;POSTGRES_HOST_AUTH_METHOD=trust&quot; to allow all
  db_1   |        connections without a password. This is *not* recommended.
  db_1   |
  db_1   |        See PostgreSQL documentation about &quot;trust&quot;:
  db_1   |        https://www.postgresql.org/docs/current/auth-trust.html
  db_1 exited with code 1
  web_1  | Watching for file changes with StatReloader
  web_1  | Performing system checks...
  web_1  |
  web_1  | System check identified no issues (0 silenced).
  web_1  | Exception in thread django-main-thread:
  web_1  | Traceback (most recent call last):
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 219, in ensure_connection
  web_1  |     self.connect()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 200, in connect
  web_1  |     self.connection = self.get_new_connection(conn_params)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/base.py&quot;, line 187, in get_new_connection
  web_1  |     connection = Database.connect(**conn_params)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py&quot;, line 122, in connect
  web_1  |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  web_1  | psycopg2.OperationalError: could not translate host name &quot;db&quot; to address: Temporary failure in name resolution
  web_1  |
  web_1  |
  web_1  | The above exception was the direct cause of the following exception:
  web_1  |
  web_1  | Traceback (most recent call last):
  web_1  |   File &quot;/usr/local/lib/python3.10/threading.py&quot;, line 1009, in _bootstrap_inner
  web_1  |     self.run()
  web_1  |   File &quot;/usr/local/lib/python3.10/threading.py&quot;, line 946, in run
  web_1  |     self._target(*self._args, **self._kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/autoreload.py&quot;, line 64, in wrapper
  web_1  |     fn(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/core/management/commands/runserver.py&quot;, line 121, in inner_run
  web_1  |     self.check_migrations()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/core/management/base.py&quot;, line 486, in check_migrations
  web_1  |     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/migrations/executor.py&quot;, line 18, in __init__
  web_1  |     self.loader = MigrationLoader(self.connection)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/migrations/loader.py&quot;, line 53, in __init__
  web_1  |     self.build_graph()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/migrations/loader.py&quot;, line 220, in build_graph
  web_1  |     self.applied_migrations = recorder.applied_migrations()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/migrations/recorder.py&quot;, line 77, in applied_migrations
  web_1  |     if self.has_table():
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/migrations/recorder.py&quot;, line 55, in has_table
  web_1  |     with self.connection.cursor() as cursor:
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 259, in cursor
  web_1  |     return self._cursor()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 235, in _cursor
  web_1  |     self.ensure_connection()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 218, in ensure_connection
  web_1  |     with self.wrap_database_errors:
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/utils.py&quot;, line 90, in __exit__
  web_1  |     raise dj_exc_value.with_traceback(traceback) from exc_value
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 219, in ensure_connection
  web_1  |     self.connect()
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/base/base.py&quot;, line 200, in connect
  web_1  |     self.connection = self.get_new_connection(conn_params)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/utils/asyncio.py&quot;, line 33, in inner
  web_1  |     return func(*args, **kwargs)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/django/db/backends/postgresql/base.py&quot;, line 187, in get_new_connection
  web_1  |     connection = Database.connect(**conn_params)
  web_1  |   File &quot;/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py&quot;, line 122, in connect
  web_1  |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  web_1  | django.db.utils.OperationalError: could not translate host name &quot;db&quot; to address: Temporary failure in name resolution
  web_1  |
  
  
  
  
  
  links:
    - db:db
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>docker-copmpose.yaml</p>
  <pre><code>version: &quot;3.9&quot;
     
  services:
    db:
      image: postgres
      volumes:
        - ./data/db:/var/lib/postgresql/data
    web:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/code
      ports:
        - &quot;8000:8000&quot;
      environment:
        - POSTGRES_NAME=postgres
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
      depends_on:
        - db
  </code></pre>