Error: incomplete startup packet, docker, postgresql, phoenix

时间:2018-07-24 10:15:17

标签: postgresql docker docker-compose phoenix-framework

I have a problem running my dockerized phoenix application with postgresql.

I specified my docker-compose.yml file to include two services: my phoenix service, build by a dockerfile and a latest postgres image taken from docker hub.

My dockerfile for phoenix looks like this:

# base image elixer to start with
FROM elixir:1.6

# install hex package manager
RUN mix local.hex --force
RUN mix local.rebar --force

# install the latest phoenix 
RUN mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez --force

# create app folder
RUN mkdir /app
COPY ./my_app /app
WORKDIR /app

# install dependencies
RUN mix deps.get

# run phoenix in *dev* mode on port 4000
# CMD mix phx.server

Here is the error:

phoenix_1  | 
phoenix_1  | 10:07:19.148 [error] GenServer #PID<0.234.0> terminating
phoenix_1  | ** (RuntimeError) Connect raised a KeyError error. The exception details are hidden, as
phoenix_1  | they may contain sensitive data such as database credentials.
phoenix_1  | 
phoenix_1  |     (elixir) lib/keyword.ex:377: Keyword.fetch!/2
phoenix_1  |     (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.startup/2
phoenix_1  |     (postgrex) lib/postgrex/protocol.ex:504: Postgrex.Protocol.handshake/2
phoenix_1  |     (db_connection) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
phoenix_1  |     (connection) lib/connection.ex:622: Connection.enter_connect/5
phoenix_1  |     (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
phoenix_1  | Last message: nil
phoenix_1  | State: Postgrex.Protocol
db         | 2018-07-24 10:07:19.149 UTC [28] LOG:  incomplete startup packet
phoenix_1  | ** (Mix) The database for MyApp.Repo couldn't be created: an exception was raised:
phoenix_1  |     ** (RuntimeError) Connect raised a KeyError error. The exception details are hidden, as
phoenix_1  | they may contain sensitive data such as database credentials.
phoenix_1  | 
phoenix_1  |         (elixir) lib/keyword.ex:377: Keyword.fetch!/2
phoenix_1  |         (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.startup/2
phoenix_1  |         (postgrex) lib/postgrex/protocol.ex:504: Postgrex.Protocol.handshake/2
phoenix_1  |         (db_connection) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
phoenix_1  |         (connection) lib/connection.ex:622: Connection.enter_connect/5
phoenix_1  |         (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

My docker-compose.yml file looks like this:

version: '3.6'
services:
  phoenix:
    build:
      context: .
      dockerfile: Dockerfile.phoenix.development
    ports:
      - 4000:4000
    volumes:
      - ./my_app:/app
    depends_on:
      - db
      - redis
    environment:
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      FACEBOOK_CLIENT_ID: ${FACEBOOK_CLIENT_ID}
      FACEBOOK_CLIENT_SECRET: ${FACEBOOK_CLIENT_SECRET}
    command: mix ecto.create && mix ecto.migrate && mix phx.server
  db:
    container_name: db
    restart: always
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_PASSWORD="some_pass"
      - POSTGRES_USER="some_user"
    volumes:
      - ./data/db:/data/db

I'm able to run my phoenix app on localhost just fine without docker.

When I set this up with docker and docker-compose, I remember to switch the dev.exs file to reference the host "db".

I wondering if this is an issue with my postgresql setup or my phoenix app setup

0 个答案:

没有答案