gpt4 book ai didi

docker - 如何将docker-compose应用部署到heroku?

转载 作者:行者123 更新时间:2023-12-02 19:51:02 24 4
gpt4 key购买 nike

我想将python django dockerapp部署到heroku。但是在psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known之后出现了git push heroku master错误。

文件如下。

我该如何解决这个问题?谢谢。

  • docker-compose.yml

  • version: '3'

    services:
    db:
    image: postgres
    environment:
    POSTGRES_DB: testdb
    POSTGRES_USER: testuser
    POSTGRES_PASSWORD: testpw

    web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
    - .:/code
    ports:
    - "8000:8000"
    depends_on:
    - db
  • heroku.yml

  • setup:
    addons:
    - plan: heroku-postgresql
    as: db
    config:
    S3_BUCKET: db
    build:
    docker:
    web: Dockerfile
    run:
    web: python manage.py runserver 0.0.0.0:8000
    worker:
    image: web
  • 我运行的命令:

  • git init ; git add -A ; git commit -m .
    heroku create # // nameless-anchorage-47384
    heroku git:remote -a nameless-anchorage-47384
    heroku stack:set container
    git push heroku master ; heroku logs --tail
  • 我得到的日志:
  • 2020-03-14T02:49:34.183660+00:00 heroku[web.1]: Starting process with command `/bin/sh -c python\ manage.py\ runserver\ 0.0.0.0:8000`
    2020-03-14T02:49:36.844857+00:00 app[web.1]: Watching for file changes with StatReloader
    2020-03-14T02:49:36.845227+00:00 app[web.1]: Performing system checks...
    2020-03-14T02:49:36.845228+00:00 app[web.1]:
    2020-03-14T02:49:36.931900+00:00 app[web.1]: System check identified no issues (0 silenced).
    2020-03-14T02:49:37.084523+00:00 app[web.1]: Exception in thread django-main-thread:
    2020-03-14T02:49:37.084566+00:00 app[web.1]: Traceback (most recent call last):
    2020-03-14T02:49:37.084603+00:00 app[web.1]: File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    2020-03-14T02:49:37.084974+00:00 app[web.1]: self.connect()
    2020-03-14T02:49:37.085013+00:00 app[web.1]: File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 195, in connect
    2020-03-14T02:49:37.085282+00:00 app[web.1]: self.connection = self.get_new_connection(conn_params)
    2020-03-14T02:49:37.085316+00:00 app[web.1]: File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
    2020-03-14T02:49:37.085892+00:00 app[web.1]: connection = Database.connect(**conn_params)
    2020-03-14T02:49:37.085931+00:00 app[web.1]: File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
    2020-03-14T02:49:37.086645+00:00 app[web.1]: conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    2020-03-14T02:49:37.086785+00:00 app[web.1]: psycopg2.OperationalError: could not translate host name "db" to address: Name or service not known
    2020-03-14T02:49:37.086810+00:00 app[web.1]:
    2020-03-14T02:49:37.086836+00:00 app[web.1]:
    2020-03-14T02:49:37.086836+00:00 app[web.1]: The above exception was the direct cause of the following exception:
    2020-03-14T02:49:37.086837+00:00 app[web.1]:

    最佳答案

    我认为你不能。我必须做免费的“Postgres插件”,然后使用它们公开的DATABASE_URL环境变量连接到数据库。

    关于docker - 如何将docker-compose应用部署到heroku?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60679382/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com