Mulitple Docker Compose: fetch fails with error 'getaddrinfo EAI_AGAIN' - node.js

I have a project, where frontend and backend are separated. I've managed to connect those apps via docker network. But now I'm stuck with error from frontend app
FetchError: request to http://nginx:80/Api/Pages/GetHeaderMenuElements/ failed, reason: getaddrinfo EAI_AGAIN nginx
docker-compose.yml for frontend:
version: '3.5'
services:
next:
container_name: ${APP_NAME:?err}-next
#restart: 'always'
#ports:
# - "41000:4000"
build:
context: .
dockerfile: Dockerfile
command: tail -F anything
networks:
default:
external:
name: 'custom-net'
docker-compose.yml for backend:
version: '3'
services:
#some services were removed
php:
restart: always
links:
- mariadb
- memcache
- mailer
build:
context: .
dockerfile: ./docker/php.Dockerfile
container_name: ${APP_NAME:?err}-php
volumes:
- './etc/php/php.ini-production:/usr/local/etc/php/php.ini'
- './www/:/var/www/html'
nginx:
image: nginx:latest
container_name: ${APP_NAME:?err}-nginx
restart: always
ports:
- '11000:80'
- '44443:443'
links:
- 'php'
volumes:
- './www:/var/www/html'
- './config/nginx/fastcgi.conf:/etc/nginx/fastcgi.conf'
- './config/nginx/nginx.conf:/etc/nginx/nginx.conf'
- './config/nginx/snippets/:/etc/nginx/snippets/'
- './config/nginx/conf:/etc/nginx/conf.d/'
networks:
default:
external:
name: 'custom-net'
I'm able to reach nginx from next container via wget.
So my question is: how can I connect to nginx?
I'm using docker for windows

Related

Backend can't query dockerized postgresql

I'm running my containers via a docker compose file. They are in the same network and I can ping from my backend container to my database container. I use the database name as the hostname in the connection string and it doesn't bring any errors that it couldn't find the host. Instead, it just hangs up and times out.
I have a test endpoint which is just suppose to test the connection. When you use that endpoint, database container logs "invalid packet length", and on the frontend, nothing happens, then it times out. I have no idea whats wrong. Any help?
version: '3.2'
services:
server:
restart: always
build:
dockerfile: Dockerfile
context: ./nginx
depends_on:
- backend
- frontend
- database
ports:
- '5000:80'
networks:
- app_network
database:
image: postgres:latest
container_name: database
ports:
- "5432:5432"
restart: always
hostname: database
environment:
POSTGRES_PASSWORD: 1234
POSTGRES_USER: postgres
backend:
build:
context: ./backend
dockerfile: ./Dockerfile
image: kalendae:backend
hostname: backend
container_name: backend
environment:
- WAIT_HOSTS=database:5432
- DATABASE_HOST=database
- DATABASE_PORT=5432
- PORT=5051
frontend:
build:
context: ./frontend
dockerfile: ./Dockerfile
image: kalendae:frontend
hostname: frontend
container_name: frontend
environment:
- WAIT_HOSTS=backend:5051
- REACT_APP_BACKEND_HOST=localhost
- REACT_APP_BACKEND_PORT=5051

Can't get docker-compose networking to work

I'm trying to make requests to my server container from my client app in another container. The Docker Compose docs state that the network is setup automatically, so shouldn't all ports be accessible from all containers? When I make a curl request to port 4000 from outside of the container (in a fresh terminal), it works. However when I enter the client container (selektor-client) and try the same request, it fails.
curl --request POST http://localhost:4000/api/music
What am I doing wrong?
docker-compose.yaml:
version: "3"
services:
client:
container_name: selektor-client
restart: always
build: ./client
ports:
- "3000:3000"
volumes:
- ./client/:/client/
- /client/node_modules/
command: ["yarn", "start"]
server:
container_name: selektor-server
restart: always
build: ./server
ports:
- "4000:4000"
volumes:
- ./server/:/server/
depends_on:
- mongo
command: ["yarn", "start"]
mongo:
container_name: selektor-mongo
command: mongod --noauth
build: .
restart: always
volumes:
# - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
- data-volume:/data/db
ports:
- "27017:27017"
volumes:
data-volume:
When you call containers of the same stack each other, the host name is, by default, the service name, and the port is the internal port: <servicename>:<internal_port>. So, based on this part of your example:
version: "3"
server:
container_name: selektor-server
restart: always
build: ./server
ports:
- "4000:4000"
volumes:
- ./server/:/server/
depends_on:
- mongo
command: ["yarn", "start"]
The url you client have to use to reach the server is http://server:4000
I had the same problem . my solution was registering network and giving subnet mast to the network and register the static ip to each container :
version: "3"
networks:
my_network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/24
services:
mongodb:
image: mongo:4.2.1
container_name: mongo
command: mongod --auth
hostname: mongo
networks:
my_network:
ipv4_address: 172.20.0.5
volumes:
- /data/db/mongo:/data/db
ports:
- "27017:27017"
rabitmq:
hostname: rabbitmq
container_name: rabbitmq
image: rabbitmq:latest
networks:
my_network:
ipv4_address: 172.20.0.3
volumes:
- /var/lib/rabbitmq:/data/db
ports:
- "5672:5672"
- "15672:15672"
restart: always
you can access through IP addresses

Error: getaddrinfo ENOTFOUND with docker-compose server definition

I'm building a react, Node App and I'm using docker-compose my docker compose definition looks like this:
version: "3"
services:
frontend:
stdin_open: true
container_name: firestore_manager
build:
context: ./client/firestore-app
dockerfile: DockerFile
image: rasilvap/firestore_manager
ports:
- "3000:3000"
volumes:
- ./client/firestore-app:/app
environment:
- BACKEND_HOST=backend
- BACKEND_PORT=8081
depends_on:
- backend
backend:
container_name: firestore_manager_server
build:
context: ./server
dockerfile: Dockerfile
image: rasilvap/firestore_manager_server
ports:
- "8081:8081"
volumes:
- ./server:/app
environment:
- BACKEND_HOST=backend
- BACKEND_PORT=8081
I'm trying to access to the NodeJs backend endpoints using the backend prefix defined in the docker-compose file, but I'm getting an Error: getaddrinfo ENOTFOUND firestore_manager_server, the same is happening using the container name: firestore_manager_server.
As you can see in the next urls:
firestore_manager_server:8081/firestore?collection=test&field=nombre&value=xxxx
backend:8081/firestore?collection=test&field=nombre&value=xxxx
I don't have any problem using localhost.
The next is the result of the docker ps command:
Any ideas?
I believe your url should be
frontend:8081/firestore?collection=test&field=nombre&value=xxxx
instead of
firestore_manager_server:8081/firestore?collection=test&field=nombre&value=xxxx

Backend container can't connect to database - Sequelize, Node, Postgres, Docker

When I try to connect my backend (using Sequelize) I get this following error:
error ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
docker-compose.yml:
version: "3.7"
services:
frontend:
build:
context: ./client
dockerfile: Dockerfile
image: client
ports:
- "3000:3000"
volumes:
- ./client:/usr/src/app
backend:
build:
context: ./server
dockerfile: Dockerfile
image: server
ports:
- "8000:8000"
volumes:
- ./server:/usr/src/app
db:
image: postgres
environment:
POSTGRES_DB: ckl
POSTGRES_USER: postgres
POSTGRES_PASSWORD: docker
ports:
- "5432:5432"
What am I doing wrong ?
Thanks in advance
Assuming your backend is connecting to the db you should add a depends_on:
backend:
build:
context: ./server
dockerfile: Dockerfile
image: server
depends_on:
- db
ports:
- "8000:8000"
volumes:
- ./server:/usr/src/app
The db will now be accessible at the host db:5432 if your application is configured to connect to localhost:5432 or 172.0.0.1:5432 you'll need to replace the hostname localhost with db. Your postgres connection string might also not have a host and might be trying to connect to localhost by default. Should be able to look at sequelize to figure out how to pass a host.

Calling service from one docker container to other container is causing net::ERR_NAME_NOT_RESOLVED

i am running application with multi containers as below..
feeder - is a simple nodejs container from image node:alpine
api - is nodejs container with expressjs from image node:alpine
ui-app - is react app container from image node:alpine
i am trying to call the api service in ui-app i am getting error as below
image to Console Log
image to Console Log
not sure what is causing the problem
if i access the services as http://192.168.99.100/ping it works (that is my docker machine default ip)...
but if i use container name like http://api:3200/ping it is not working...? please help..
the below is my docker-compose.
version: '3'
services:
feeder:
build: ./feeder
container_name: feeder
tty: true
depends_on:
- redis
links:
- redis
environment:
- IS_FROM_DOCKER=true
ports:
- "3100:3100"
networks:
- hmdanet
api:
build: ./api
container_name: api
tty: true
depends_on:
- feeder
links:
- redis
environment:
- IS_FROM_DOCKER=true
ports:
- "3200:3200"
networks:
hmdanet:
aliases:
- "hmda-api"
ui-app:
build: ./ui-app
container_name: ui-app
tty: true
depends_on:
- api
links:
- api
environment:
- IS_FROM_DOCKER=true
ports:
- "3000:3000"
networks:
- hmdanet
redis:
image: redis:latest
ports:
- '6379:6379'
networks:
- hmdanet
networks:
hmdanet:
driver: bridge
You can only use service name as a domain name when you are inside a container. In you case it's your browser making the call, it does not know what api is. In you web app, you should have an env like base url set to the ip of your docker machine or localhost.

Resources