Reputation: 45
I have 3 different containers which are as below 1. UI Container having Vue SPA 2. Backend Container having Spring Boot application 3. MYSql DB container
below is my docker-compose file
version: '3'
services:
mysqldb:
image: mysql:latest
container_name: mysqldb
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: simple-bug
ports:
- "3306:3306"
simple-bug-back:
build: ./..
container_name: simple-bug-back
ports:
- "8082:8082"
restart: on-failure
depends_on:
- mysqldb
environment:
SPRING_PROFILES_ACTIVE: dev
SPRING_DATASOURCE_URL: jdbc:mysql://mysqldb/simple-bug
simple-bug-ui:
build: ./../ui
ports:
- "8080:8080"
depends_on:
- simple-bug-back
Now I am trying to access
in vue application but it is giving net::ERR_NAME_NOT_RESOLVED but if i try the same inside container i.e.
docker exec -it docker_simple-bug-ui_1 sh
and execute curl command inside that for above URL I am getting the response
Can anyone help me what am I missing
Upvotes: 0
Views: 557
Reputation: 45
To resolve the above issue, I used Nginx as my server (https://v2.vuejs.org/v2/cookbook/dockerize-vuejs-app.html) and used it's reverse proxy. I levarage the .env file to route all my request to particular uri for all my backend call (in my case /back/) and below is my nginx.conf file
upstream spring_back_8082 {
server simple-bug-back:8082;
}
server {
..
..
location / {
try_files $uri $uri/ =404;
}
location /back/ {
proxy_pass http://spring_back_8082/;
}
}
Now to call backend my url is /back/...
Upvotes: 0
Reputation: 46
The reason is because your host doesn't know the container by this domain, this domain is valid only into network cretated for to containers by docker-compose, if you want use this domain you should add it into your /etc/hosts file like this (because you have exposed the port 8082):
127.0.0.1 simple-bug-back
Upvotes: 1