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).
Trending in Questions
Other Trending Topics
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 19 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Again, very likely it’s because their
docker-compose.yamlfile 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
yeah, it’s interesting that they specify the ports in the
dockercommands, but not in thedocker-compose.ymldimitarvp
…btw the
README.mdalso has this in it:So even they use the host:container port specification format.
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
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
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
It is random if he didn’t change the
portspart 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
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
Interesting. Ok, I get a lot of errors, but after running those, it works.
@dimitarvp I can connect using
psqlor 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
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 rundocker psjust to make sure as well.