AUGERClement
Hello.
I’m trying to learn Docker to container my basic API.
The steps I did are the following :
- Create the API, test it with a postman etc.
- Mix phx.gen.secret (let’s assume SECRET as a value for after)
- As my API has no assets, I didn’t have to compile them.
- Mix phx.gen.release —docker
- Removed lines from Dockerfile which interact with assets
- Docker build
docker run -e DATABASE_URL="ecto://postgres:postgres@localhost/database_dev"
-e SECRET_KEY_BASE=SECRET -p 4000:4000 imageID
I tried multiples variations with my ip instead of localhost, the HOST argument, —network=host, etc. But the error is still
16:36:50.497 [error] Postgrex.Protocol (#PID<0.1887.0>)
failed to connect: ** (DBConnection.ConnectionError) tcp connect
(my_ip:5432): connection refused - :econnrefused
After looking for a bit, I found out that the problem may come from docker permissions, but I couldn’t find anymore stuff.
I feel like I messed up some really basic step, but I can’t find it alone.
Can someone tell me where I did wrong ?
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
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
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Exadra37
You need to provide us with your Dockerfile(s), and Elixir config files in order for us to be able to understand what is wrong.
smita
Hi,
the problem is
localhostinDATABASE_URL. The URL is resolved inside the docker and there is no postgress.AUGERClement
First, the dockerfile is the following, direcly generated by phoenix. I commented assets related stuff (compile and deploy)
Second, I did try with my ip in DATABASE_URL, but nothing changed.
My end goal would be to use docker compose with my app and postgres as services. But trying to use compose when I can’t make a container run correctly seem a bit out of order.
stefanchrobot
Are you trying to connect from the Docker container to the DB that’s running locally? That won’t work by default, you’ll need to open up some ports (sorry, you’ll need to peek into the Docker docs).
Doing this with Docker Compose might actually be easier as it will set some things up for you. Here’s an example (not tested):
AUGERClement
I’m on another project rn, but many thanks, I’ll try this as soon as possible
trisolaran
You can connect to services running on the host machine from a docker container directly using the special hostname:
host.docker.internalSee: https://docs.docker.com/desktop/windows/networking/#use-cases-and-workarounds
(the link is about Windows, but it also works on Mac)
akashv
For linux you will need to add following line to your service needs to access localhost-
Exadra37
Using the
nobodyuser is not advised from a security perspective, androotshouldn’t really be used at all.And was then updated here:
AUGERClement
I read about this issue. But wouldn’t it become rather complex to set up another user (let’s say phoenix) before dropping your docker + compose ?
Doesn’t it defeat the whole point of the “Deploy everywhere” thing ?
AUGERClement
Ok so after trying your thing and many others similar I found across the week, my compose.yml look like that rn :
Now, it seem I can connect the DB because I have those logs for the db service:
along with those for the phoenix app:
For anyone strumbling upon this subject, what I didn’t get was that the service name “db” should be used instead of the IP in the URL.
I’ll mark your answer as solution.