I’m setting up Laravel API and Nuxt front end with docker-compose. I have in two seperate projects (and two docker-compose.yml) and I connect them through network. The problem is that when I make some call to API on Nuxt’s server side, API hostname is Laravel’s service, but on client side the service is unaccessible.
API is mapped from port 80 in container to 8080 on my host. On client side, I can access API by calling http://localhost:8080/api/ but I also do some calls on Nuxt server side, which does not have access to host from container, so it has to call API on http://app-dev/api
#backend.yml
version: '3.5'
services:
database:
image: mariadb:10.3
networks:
- my-network
#...
app-dev:
depends_on:
- "database"
ports:
- 8080:80
networks:
- my-network
#...
networks:
my-network:
name: my-network
#------------------------
#frontend.yml
version: '3.5'
services:
front-app-dev:
ports:
- ${FRONTEND_SERVER_PORT}:${FRONTEND_SERVER_PORT}
networks:
- my-network
#...
networks:
my-network:
external: true
How can I unify calling API from server side and client side? Is there some way to make host’s port 8080 accessible in front-app-dev, so server side can make calls there?
My Docker version is 18.06.1-ce, OS Ubuntu 19, but solution has to work also on Windows and MacOS.