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

问题描述 投票:0回答:1

我想将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]:
docker heroku
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.