Error: getaddrinfo ENOTFOUND with docker-compose server definition - node.js

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

Related

Docker compose, accessing a Postgres container from an other container

I have this really simple setup with a web app in one container and a Postgres service running in another container.
I need to connect to the Postgres container and thought PGHOST="db" would point to that container ..?
But I keep getting Error: getaddrinfo ENOTFOUND "db" at GetAddrInfoReqWrap.onlookup that I read as; can't find the "db" host ...
What am I missing here?
version: "3.9"
services:
web:
build: .
ports:
- "8081:3011"
links:
- db
environment:
- PGHOST="db"
- PGDATABASE="testdb"
- PGUSER="postgres"
- PGPASSWORD="postgres"
db:
image: postgres
ports:
- "5432:5432"
volumes:
- /usr/local/var/postgresql#13
Try this config. You don't need quotes when passing env variables. And it is better to use depends_on here to make sure DB is up and running before your app starts.
version: "3.9"
services:
web:
build: .
ports:
- "8081:3011"
depends_on:
- db
environment:
- PGHOST=db
- PGDATABASE=testdb
- PGUSER=postgres
- PGPASSWORD=postgres
db:
image: postgres
ports:
- "5432:5432"
volumes:
- /usr/local/var/postgresql#13

Mulitple Docker Compose: fetch fails with error 'getaddrinfo EAI_AGAIN'

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

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

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