I created this docker-compose for my application:
version: "3.9"
services:
db:
image: postgres:15-alpine
container_name: db
expose:
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- db:/var/lib/postgresql/data
restart: 'always'
networks:
- backend_network
user:
container_name: user-management
build:
context: ./user-management
dockerfile: Dockerfile-dev
ports:
- "5000:5000"
expose:
- 5000
depends_on:
- db
env_file:
- ./user-management/.env.dev
volumes:
- /tmp/user-management/npm-cache:/root/.npm:z
- ./user-management/src:/usr/src/user-management/src
networks:
- frontend_network
- backend_network
restart: 'no'
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile-dev
environment:
- NEXT_PUBLIC_USER_MANAGEMENT_URL=${NEXT_PUBLIC_USER_MANAGEMENT_URL}
ports:
- "3000:3000"
networks:
- frontend_network
depends_on:
- user
- quiz
restart: 'no'
volumes:
- ./frontend/public:/usr/src/frontend/public
- ./frontend/src:/usr/src/frontend/src
volumes:
db:
driver: local
networks:
frontend_network:
backend_network:
driver: bridge
in the .env
file I set NEXT_PUBLIC_USER_MANAGEMENT_URL=http://user:5000
but the call from the frontend does not work.
The call is successfull only if I change it to localhost:5000
.
What’s wrong with my config to use make a call form frontend to backed using docker dns?