Hi everyone,
I am building an Elixir Umbrella app and I want to “dockerise” it for later deployment.
For now it just consist of a single, simple Phoenix API with a postgre DB. But it will grow with multiple apps in the future.
I followed this tutorial in order to use Docker but it does not provide me with an example on how to setup a DB in my Docker image & container.
Hence, I eventualy ran into this error when trying to run my Docker image:
15:57:24.782 [error] Postgrex.Protocol (#PID<0.1353.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
15:57:24.784 [error] Postgrex.Protocol (#PID<0.1352.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
15:57:24.785 [error] Postgrex.Protocol (#PID<0.1358.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
15:57:24.786 [info] Running ComitiaWeb.Endpoint with cowboy 2.6.1 at :::4000 (http)
15:57:24.786 [error] Postgrex.Protocol (#PID<0.1357.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
etc.
How can I change my Dockerfile (and other files if required) to create a DB in my Docker containers ?
Here is my Dockerfile
:
# Alias this container as builder:
FROM bitwalker/alpine-elixir-phoenix as builder
WORKDIR /political_project
ENV MIX_ENV=prod
# Umbrella
# Copy mix files so we use distillery:
COPY mix.exs mix.lock ./
COPY config config
COPY apps apps
RUN mix do deps.get, deps.compile
WORKDIR /political_project
COPY rel rel
RUN mix release --env=prod --verbose
FROM alpine:3.9
RUN apk upgrade --no-cache && \
apk add --no-cache bash openssl
# we need bash and openssl for Phoenix
EXPOSE 4000
ENV PORT=4000 \
MIX_ENV=prod \
REPLACE_OS_VARS=true \
SHELL=/bin/bash
WORKDIR /political_project
COPY --from=builder /political_project/_build/prod/rel/political_project/releases/0.1.0/political_project.tar.gz .
RUN tar zxf political_project.tar.gz && rm political_project.tar.gz
RUN chown -R root ./releases
USER root
CMD ["/political_project/bin/political_project", "foreground"]