2017-02-12 12 views
1

Dockerを初めて使いました。このチュートリアルの後:https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/Dockang Djangoがサーバーに接続できませんでした:Connection refused

私のコードのほとんどはチュートリアル(https://github.com/realpython/dockerizing-django)と同じです。いくつかのマイナーチェンジがあります。

この私のdocker-compose.yml

web: 
    restart: always 
    build: ./web 
    expose: 
    - "8000" 
    links: 
    - postgres:postgres 
    - redis:redis 
    volumes: 
    - /usr/src/app 
    - /usr/src/app/static 
    env_file: .env 
    environment: 
    DEBUG: 'true' 
    command: /usr/local/bin/python manage.py runserver 

nginx: 
    restart: always 
    build: ./nginx/ 
    ports: 
    - "80:80" 
    volumes: 
    - /www/static 
    volumes_from: 
    - web 
    links: 
    - web:web 

postgres: 
    restart: always 
    image: postgres:latest 
    ports: 
    - "5432:5432" 
    volumes: 
    - pgdata:/var/lib/postgresql/data/ 

redis: 
    restart: always 
    image: redis:latest 
    ports: 
    - "6379:6379" 
    volumes: 
    - redisdata:/data 

(私はデバッグ目的のrunserverするgunicornコマンドを変更し)、これはジャンゴの私のsettings.pyである:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'postgres', 
     'USER': 'postgres', 
     'PASSWORD': 'postgres', 
     'HOST': 'postgres', 
     'PORT': '5432', 
    } 
} 

nginxのとpostgresの(とRedisの)は起動していますが、私のdjangoサーバはこのエラーによって起動しません:

web_1  | django.db.utils.OperationalError: could not connect to server: Connection refused 
web_1  | Is the server running on host "localhost" (::1) and accepting 
web_1  | TCP/IP connections on port 5432? 
web_1  | could not connect to server: Connection refused 
web_1  | Is the server running on host "localhost" (127.0.0.1) and accepting 
web_1  | TCP/IP connections on port 5432? 

私はたくさんグーグルで行きました。私はpostgresが動作していることを確認しました。ポート5432でpsqlコマンドを使用して接続できます。

紛失しています。私の間違いは何ですか?

EDIT:サーバがローカルホスト上で動作しているかどうかを尋ねるので、settings.pyファイルなどを使用していないようですが、設定はポストグルを探している必要があります。そのような行が存在しない場合、 は

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") 

ラインがあるはず、

PYTHONPATHに関してごDJANGO_SETTINGS_MODULEを設定し、それを

答えて

0

チェックアウトあなたのmanage.pyを置きます。

UPDは、私はあなたのレポをクローニングして、私はDJANGO_SETTINGS_MODULEが正しいことを確信しているドッキングウィンドウ-compose.yml

- command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000 
+ command: python manage.py runserver 0.0.0.0:8000 

でコマンドを変更することにより、Webサービスを開始しました。

+0

返信いただきありがとうございますが、その行はあります!すべてがローカルで動作します。 –

+0

@あなたの更新は、それが正しいです。そして、私が言及したレポは、私のために箱の中で働いています:)。私はそれを有効にすることができたが、どのくらい正確にはわからない。 –

関連する問題