I am using docker-compose to set up a NextJS-app that fetches data from the Wordpress REST-API running in separate containers.
Problem is, I get ECONNREFUSED
when I try to fetch or WGET the wordpress-container http://wordpress:8000 from the NextJS-container. I can ping wordpress:8000 without any problems.
If I use Postman or try to fetch the REST-API from another host (i.e. not the machine running docker-compose) using the public ip, it works perfectly.
I'm suspecting some docker configuration issue, but I'm quite lost as the pinging works but not the wget.
Anyone with an idea on what the culprit could be?
My docker-compose.yml:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ***REMOVED***
MYSQL_DATABASE: ***REMOVED***
MYSQL_USER: ***REMOVED***
MYSQL_PASSWORD: ***REMOVED***
networks:
- back
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./wp-content:/var/www/html/wp-content
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: ***REMOVED****
networks:
- back
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8080:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ***REMOVED***
networks:
- back
next-app:
depends_on:
- wordpress
build:
context: ./next-app
dockerfile: Dockerfile
volumes:
- './next-app:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- '80:3000'
networks:
- back
express-server:
build:
context: ./express-server
dockerfile: Dockerfile
ports:
- '3001:3001'
networks:
back:
driver: bridge
volumes:
db_data:
From inside the NextJS container, you need to use port 80
. Port 8000
is at your's (host) machine.
That means you need to use http://wordpress:80
from inside the docker containers.
Ports section in you docker-compose file
ports:
- "8000:80"
mean: "Map my local (host machine) port 8000
to container's ports 80
", but inside the docker network, it's still port 80
You can ping because ping doesn't use ports. Ports that we are talking about are TCP/UDP ports, see Wikipedia | Port. Ping uses ICMP (Internet Control Message Protocol), not TCP or UDP; ICMP doesn't use ports at all. See Wikipeadia | Ping