sc4224
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
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
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
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
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 21 to 12- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
I mean this:
But Okay, you are using a relative path there, so its not that bad as I thought. Still I strictly prefer named volumes which are then managed by docker.
sc4224
I finally got it to work with docker-compose up and docker-compose down, thanks a lot
cnck1387
It doesn’t crash for me with the example in the github repo I linked.
But you could always do
docker-compose run phoenix mix ecto.create && mix ecto.migratebefore you dodocker-compose upwith your example.sc4224
when you say purge my volume, do you mean docker-compose down -v?
what do you mean by a hard volume?
NobbZ
Also, to make sure that your database has been created with the correct credentials, please purge your volume.
Also for development you really shouldn’t use hard volumes as you did. That could even interfere with a real PostgreSQL in your development machine.
NobbZ
I do not understand that one…
sc4224
What I understand here is that I should be running mix ecto.create and mix ecto.migrate before running mix phx.server. If I put these as entrypoints inside of a shell script and run this, my docker container crashes since mix phx.server depends on both ecto create and migrate commands
NobbZ
As far as I remember, that’s invalid syntax. Is just create a shell script and use that as an entry point.
sc4224
so should I do something like:
And what about the “error/warning” logs I received in my above comment, should I be concerned about those? Does this mean that postgres is not started up properly?
cnck1387
I wouldn’t put create / migrate in your Dockerfile. Those are really something you do at runtime, not build time.
I would just
docker-compose execthose commands after you up everything beforehand. Or if you were really gung-ho on having that done automatically on every container start you could put it into an entrypoint script but personally I don’t like doing that.