I have 2 folders separated, one for backend and one for frontend services:
- backend/docker-compose.yml
- frontend/docker-compose.yml
The backend has a headless wordpress
installation on nginx
, with the scope to serve the frontend as an api service. The frontend runs on next.js
. Here are the 2 different docker-compose.yml
:
backend/docker-compose.yml
version: '3.9'
services:
nginx:
image: nginx:latest
container_name: my-app-nginx
ports:
- '80:80'
- '443:443'
- '8080:8080'
...
networks:
- internal-network
mysql:
...
networks:
- internal-network
wordpress:
...
networks:
- internal-network
networks:
internal-network:
external: true
frontend/docker-compose.yml
version: '3.9'
services:
nextjs:
build:
...
container_name: my-app-nextjs
restart: always
ports:
- 3000:3000
networks:
- internal-network
networks:
internal-network:
driver: bridge
name: internal-network
In the frontend I use the fetch
api in nextjs
as following:
fetch('http://my-app-nginx/wp-json/v1/enpoint', ...)
I tried also with ports 80
and 8080
, without success.
The sequence of commands I run are:
docker network create internal-network
- in
backend/
folder,docker-compose up -d
(all backend containers run fine, I can fetch data with Postman from WordPress api) - in
frontend/ folder
,docker-compose up -d
fails with the errorError: getaddrinfo EAI_AGAIN my-app-nginx
I am not a very expert user of docker
so I might miss something here, but I understand that there might be internal network issues over the containers. I read many answers regarding this topic but I couldn't figure it out.
Any recommendations?