wdiechmann
MyXQL says failed to connect ... non-existing domain - but there is no example.com :o
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
Marked As Solved
wdiechmann
I erred on two accounts
-
I referenced
file_db(which is the container image name in my configuration) where I should have referenced the service name - because hosts are setup by default with hostname = service name - see the docker reference link below -
I quoted db in the docker-compose.yml file where I should have left the quotes out (in effect ‘promoting’ db to a local variable of sorts
# ./docker-compose.yml
version: "3"
services:
db:
image: mysql:latest
container_name: fish_db
environment:
- MYSQL_DATABASE='fish_prod'
- MYSQL_PASSWORD='another secret'
- MYSQL_USER='root'
- MYSQL_ROOT_PASSWORD='secret'
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- ./priv/repo/db:/var/lib/mysql
networks:
- db-network
server:
image: fish:latest
container_name: fish-app-server
environment:
- PORT=4000
- HOST="127.0.0.1"
- DBHOST=db
- DBNAME=fish_prod
- SECRET_KEY_BASE=fikumdick
expose:
- "4000"
ports:
- "4000:4000"
command: ./prod/rel/fish/bin/fish start
networks:
- db-network
depends_on:
- db
volumes:
fish_db: {}
networks:
db-network:
Also Liked
wdiechmann
yes
- and I should have been on to that from the start!
Composing Docker compose yml’s will allow you to reference a somewhat covert naming scheme where hosts are named by their service - in this case: db
If you put that in “” I reckon that Docker will not try to extrapolate (or whatever it does) but take the string at face value -
So yes - I should have typed db where I typed "db" - and saved Wojtech and NoobZ precious time!
my bad
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










