fireproofsocks

fireproofsocks

Dumb question and one I used to know the answer to… but how does one connect to a postgres instance running inside docker-compose? I thought I would work through Broadway’s example repo GitHub - elixir-broadway/broadway_bike_sharing_rabbitmq_example: An example of a Broadway pipeline for a bike sharing app with RabbitMQ and PostgreSQL · GitHub – it uses docker-compose to spin up both a version of Postgres (one specifically with postgis installed) and an instance of RabbitMQ.

docker-compose up seems to have worked… no errors, and Docker Desktop shows 3 containers: rabbitmq-1, db-1, and app-1. RabbitMQ and Postgres are running, but the app has crashed because it can’t connect to the database.

Looking more closely, it seems like the port directive in docker-compose.yml is being ignored. I’ve deleted the images and rebuilt this several times in the course of testing it, and each time the ports used come up with something more random (?) like 53665. If I set my database client to use that port, I can connect.

Can someone clarify why this port is changing? And I seem to remember that the list of services defined inside of the docker-compose.yml corresponded to hostnames? Is that accurate? Like, instead of localhost, you might reference a hostname of db – but that doesn’t seem to work (even if I use the numeric extension).

Showing Posts 19 to 10

dimitarvp

dimitarvp

Again, very likely it’s because their docker-compose.yaml file is used for CI/CD and deployment, not for local development, that’s my hypothesis. If it was used for local dev then surely it would have the host:container port pairs.

fireproofsocks

fireproofsocks OP

yeah, it’s interesting that they specify the ports in the docker commands, but not in the docker-compose.yml :thinking:

dimitarvp

dimitarvp

…btw the README.md also has this in it:

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

So even they use the host:container port specification format.

dimitarvp

dimitarvp

They likely don’t plan on connecting to the containerized services from the host at all, hence their configuration.

I personally disagree with that choice of theirs but they have a point as well – they have produced something that works and they don’t see why you would need to poke inside it.

In your case however you can change the configuration very easily so I am not sure why do we keep debating the same thing in several different ways.

fireproofsocks

fireproofsocks OP

I think this all points to the Broadway example repo benefiting from a pull request that makes this all a bit more straight-forward. As has been suggested here, I think this would make a lot more sense if the ports were fixed.

dimitarvp

dimitarvp

OK, but should you not specify the host port as well? It’s a trivial change. Doing this dance with the random port is not productive and I don’t understand why you keep sticking to it.

dimitarvp

dimitarvp

It is random if he didn’t change the ports part of the configuration, the version he linked to was only specifying container port which means that the host port is chosen at random every time.

D4no0

D4no0

This makes zero sense, I would recommend to check your setup, this never should happen and it’s not expected behavior, the exposed port is dictated by the configuration and it is never random.

fireproofsocks

fireproofsocks OP

Interesting. Ok, I get a lot of errors, but after running those, it works. :person_shrugging:

@dimitarvp I can connect using psql or similar, but I have to check with Docker to see which port the database is running on (because it changes each time I start it).

dimitarvp

dimitarvp

Can you try connecting to the host IP+port with psql, just to make sure that you actually can reach the DB? You can also run docker ps just to make sure as well.

Where Next? Top

Trending in Questions Top

RSP87
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
kpanic
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
nseaSeb
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
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 Top

GenericJam
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
JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews