I can't figure out what address to use when running my API service in the same container as my Postgres image. I keep getting the following error.
thread 'main' panicked at 'Error connecting to db: Io(Os { code: 99, kind: AddrNotAvailable, message: "Cannot assign requested address" })'
My current sqlx connection is the following.
let postgress_pool: Pool<sqlx::Postgres> = PgPoolOptions::new()
.max_connections(2)
.connect("postgresql://postgres:123@database:5432/users").await
.expect("Error connecting to db");
docker-compose.yml
database:
container_name: postgres-database
image: postgres
expose:
- 5432
ports:
- 5432:5432
restart: always
environment:
POSTGRES_PASSWORD: 123
POSTGRES_DB: users
volumes:
- ./init_users.sql:/docker-entrypoint-initdb.d/init.sql
auth:
container_name: auth-service
build: ./Authentication/
ports:
- 8080:8080
I've tried changing the address to the following addresses
0.0.0.0
localhost
172.17.0.1
172.18.0.1
172.18.0.3
postgres-database
database
Sidenote: I am relatively new and saw some sources say things like establishing a network in the docker-compose file but others say this isn't necessary.