I’m trying to cram my phoenix project into a couple of containers. I have a mysql-server running in a container that exposes 3306 (and which I’m able to connect to from CLI). I’ve built a container for my app with this
# BUILD STAGE
FROM bitwalker/alpine-elixir-phoenix:latest AS phx-builder
# Set exposed ports
ENV MIX_ENV=prod
RUN mkdir /app
WORKDIR /app
# Cache elixir deps
ADD mix.exs mix.lock ./
RUN mix do deps.get, deps.compile
# Same with npm deps
ADD assets/package.json assets/
RUN cd assets && \
npm install
ADD . .
# Run frontend build, compile, and digest assets
RUN cd assets/ && \
npm run deploy && \
cd - && \
mix do deps.get, deps.compile, phx.digest, release
# APPLICATION STAGE
FROM bitwalker/alpine-elixir:latest
COPY --from=phx-builder /app/_build .
RUN chmod +x ./prod/rel/fish/bin/fish
RUN mkdir ./prod/rel/fish/tmp
RUN chmod +x ./prod/rel/fish/bin/fish
EXPOSE 5000
ENV MIX_ENV=prod
ENV APP_PORT=4000
ENV COOL_TEXT="Elixir Rocks"
ENV SECRET_KEY_BASE="Aru1gpxiZDZHqt6biIsZoblCM8/yUPLy3kG9BhgcvcKUDUv5SkPhR4q/HKhZkcV7"
ENV POOL_SIZE=10
CMD ["./prod/rel/fish/bin/fish", "start"]
I can do
$ docker build -f Dockerfile.build -t fish .
but when I do
$ docker run --publish 4000:4000 --env COOL_TEXT='ELIXIR ROCKS!!!!' --env SECRET_KEY_BASE=fikumdick --env APP_PORT=4000 --env PORT_SIZE=10 --env HOST=localhost fish:latest
I get this output
15:31:11.834 [info] Running FishWeb.Endpoint with cowboy 2.7.0 at :::4000 (http)
15:31:11.835 [info] Access FishWeb.Endpoint at http://example.com
15:31:13.194 [error] MyXQL.Connection (#PID<0.3290.0>) failed to connect: ** (DBConnection.ConnectionError) non-existing domain
(and I haven’t the faintest idea where ‘it’ digs up that example.com
- I have zero mentioning of that in any file)
My config/config.exs looks like this:
# config/config.exs
use Mix.Config
config :fish,
ecto_repos: [Fish.Repo]
# Configures the endpoint
config :fish, FishWeb.Endpoint,
url: [host: {:system, "HOST"}, port: {:system, "PORT"}],
load_from_system_env: true,
secret_key_base: "nOPS8kJTmAZtcgOpGVo7fMrAbFCCUVySKShVewMdaudersQgSLszNnTqb36fm71I",
render_errors: [view: FishWeb.ErrorView, accepts: ~w(html json), layout: false],
pubsub_server: Fish.PubSub,
live_view: [signing_salt: "i1ucCSg6"]
config :fish, :pow,
user: Fish.Users.User,
repo: Fish.Repo,
extensions: [PowResetPassword],
controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks,
web_module: FishWeb,
mailer_backend: FishWeb.Pow.Mailer
config :fish, :pow_assent,
providers: [
github: [
client_id: "REPLACE_WITH_CLIENT_ID",
client_secret: "REPLACE_WITH_CLIENT_SECRET",
strategy: Assent.Strategy.Github
]
# example: [
# client_id: "REPLACE_WITH_CLIENT_ID",
# site: "https://server.example.com",
# authorization_params: [scope: "user:read user:write"],
# nonce: true,
# strategy: Assent.Strategy.OIDC
# ]
]
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
and my releases.exs looks like this
#config/releases.exs
import Config
secret_key_base = System.fetch_env!("SECRET_KEY_BASE")
cool_text = System.fetch_env!("COOL_TEXT")
application_port = System.fetch_env!("APP_PORT")
pool_size = System.fetch_env!("POOL_SIZE")
config :fish,
cool_text: cool_text
config :fish, Fish.Repo,
# ssl: true,
migration_primary_key: [name: :id, type: :binary_id],
username: "root",
password: "",
database: "fish_dev",
hostname: "fish_db",
# url: database_url,
pool_size: String.to_integer(pool_size || "10")
config :fish, FishWeb.Endpoint,
http: [:inet6, port: String.to_integer(application_port)],
secret_key_base: secret_key_base