Docker-compose with django could not translate host name “db” to address: Name or service not known

后端 未结 4 772
情书的邮戳
情书的邮戳 2020-12-10 01:57

I have currently a system built with docker-compose, it creates a Django application.

Up until now I\'ve used a database inside a container (postgresql) in my testin

相关标签:
4条回答
  • 2020-12-10 02:36

    Add network, link and depends_on configuration in docker compose file.

    example:

      services:
          db:
              build: .
              container_name: db
              networks:
                  - djangonetwork
          web:
              build: .
              depends_on:
                 - db
              links:
                 - db:db
              networks:
                 - djangonetwork
    
      networks:
          djangonetwork:
              driver: bridge
    
    0 讨论(0)
  • 2020-12-10 02:41

    To the others experiencing this.

    The following command (which removes all unused containers, networks, images, and optionally, volumes) solve my problem:

    docker system prune
    

    See docker document for more information

    0 讨论(0)
  • In the "django" part of your docker-compose.yml under "depends_on" section try adding links: - db:db after it, or even replace the depends_on: db with that.

    I'll bet if you typed in docker logs (container name) you'd see it's obviously having trouble working out where "db" points to.

    I think they're looking to end support for links in docker-compose in new iterations at least I read that somewhere..

    0 讨论(0)
  • 2020-12-10 02:57

    Answering my question, this was a stupid one...

    My manage.py was selecting only the base.py settings file, and was not taking into account the staging.py settings file. So it was breaking in the CLI and was not breaking inside the app.

    0 讨论(0)
提交回复
热议问题