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 having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
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
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
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
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










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.