How to take place name resolution. net::ERR_NAME_NOT_RESOLVED error is occurred, when using docker compose and docker network
Hello.
When I use docker compose and docker network to create frontend server and backend server and db server, net::ERR_NAME_NOT_RESOLVED
is occurred in google chrome console.
Below file is my docker-compose.yml
.
I assured that the communication of backend-container to frontend-container is no problem, because I attached to frontend-container ( using command of docker exec -it frontend-container /bin/bash
) and confirmed communication ( using command of curl backend-container:4000
).
However, when I attempted to communicate backend-container from web browser (frontend application), net::ERR_NAME_NOT_RESOLVED
is occurred in chrome developer console.
I think that name resolution is not taking place from web browser. However I have no idea how to name resolution in this case.
Please help me and teach me how to resolve name in this case. Thank you.
version: "3.5"
services:
frontend:
build:
context: "./project01_frontend"
dockerfile: "Dockerfile.prod"
container_name: frontend-container
restart: always
tty: true
ports:
- "80:80"
env_file:
- "./project01_frontend/.env"
depends_on:
- "db"
- "backend"
backend:
build:
context: "./project01_backend"
dockerfile: "Dockerfile.dev"
container_name: backend-container
restart: always
tty: true
expose:
- "4000"
env_file:
- "./project01_backend/.env"
depends_on:
- "db"
command: ["./wait-for-db-container.sh", "yarn", "start"]
db:
image: mysql:5.7.34
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
container_name: db-container
volumes:
- ./project01_backend/initdb.d:/docker-entrypoint-initdb.d
environment:
MYSQL_DATABASE: "typeorm_db"
MYSQL_ROOT_PASSWORD: "password"
TZ: "Asia/Tokyo"
restart: "always"
expose:
- "3306"
port 4000:4000
) and set the api destination of the frontend-container tolocalhost:4000
? I think this is a possible solution, but I would like to keep it within one docker network if possible. Please let me know if this is possible. Thank you much.