Reputation: 2757
I have 2 containers running:
/usr/share/nginx/html
.Why cannot I make a GET request for /search
so that this request is handled by back-end?
I always get net::ERR_CONNECTION_REFUSED
in browser's console even if I have linked them.
Here's my config:
services:
backend:
image: docker.xxxxx.net/yyyyyy/zzzzzzzz:latest
expose:
- "8080"
ports:
- "8333:8080"
frontend:
build:
dockerfile: Dockerfile
context: .
depends_on:
- "backend"
links:
- backend
ports:
- "80:80"
volumes:
- ./build:/usr/share/nginx/html
Important note that launching just back-end on another server allows me make API calls (the only problem that arises then is CORS), so the back-end code is ok and the problem must be in wrong docker configuration.
I can clearly open front-end, but I cannot make any API calls: I have tried a lot of things like to make a calls to:
http://backend/search?q=test
http://backend:8080/search?q=test
http://backend:8333/search?q=test
http://frontend/search?q=test
http://frontend:8080/search?q=test
http://frontend:8333/search?q=test
The result is the same. What can be wrong?
Upvotes: 2
Views: 1933
Reputation: 6341
I am assuming GET request is made from your browser, i.e, from the host NOT from the frontend container. As per your config, 8080 is exposed from backend container to the frontend container and port 8333 is exposed to the docker host. Hence http://backend:8080
is visible only from within frontend container but not from the host machine. So it might have to be http://<docker_ip>:8333/search?q=test
to get the response from backend container.
Upvotes: 2
Reputation: 1826
handle your CORS error with nginx.
configure in your nginx.conf a reverse proxy.
server {
listen 80 default_server;
server_name _;
location /search {
proxy_pass http://backend:8080;
}
...
}
this (or similar) should solve your net::ERR_CONNECTION_REFUSED permission error
Upvotes: 0