I struggle a bit with Docker and ports, but here's my situation. I have a Docker compose file which spins up a Postgres DB and adminer, the admin GUI. Here's my (truncated) config:
# database
db:
image: postgres:14.2
volumes:
- .psqlrc:/root/.psqlrc:ro
- dbdat:/var/lib/postgresql/data
- ./log:/root/log:cached
- ./latest.dump:/latest.dump
environment:
POSTGRES_DB: hlp-api-dev
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
DB_PORT: 5432
ports:
- 5432
healthcheck:
test: pg_isready -U postgres -h 127.0.0.1
interval: 5s
# database admin
dbAdmin:
image: adminer
ports:
- 8080
depends_on:
- db
That all works fine - but HTTP access to adminer is seemingly random port chosen by Docker e.g.
http://localhost:57014
...which I can find out only by clicking the brower button next to its container within Docker Desktop. How can I dictate this port, and why isn't it accessible at
http://localhost:8080
...which is the port listed?
If I try to specify another port, i.e.
ports:
- 8080
- 5000 # my choice
...then it doesn't spin up on any port at all. Even if I click the browser button within DD, I get "connection reset" in the browser.