Making an API call from dockerized web page to back-end server ends up with net::ERR_CONNECTION_REFUSED

I have 2 containers running:

  • a front-end nginx-based app/container (web page opened in browser) that tries to make an API call at “/search” endpoint. Webpage is static and is available by copying webpage contents into /usr/share/nginx/html.
  • a back-end server that is available on port 8080

Why cannot I make a GET request for /search so that this request is handled by back-end?

  • How to get docker volumes from newly built image?
  • Running Gatling from container
  • automatic log rotation is not executing
  • installation of nodejs returned a non-zero code: 1 with docker build
  • Fig up: Cannot find module - docker run works
  • Logging in to private docker registry v2 behind haproxy
  • I always get net::ERR_CONNECTION_REFUSED in browser’s console even if I have linked them.

    Here’s my config:

             - "8080"
             - "8333:8080"
             dockerfile: Dockerfile
             context: .
             - "backend"
             -  backend
             - "80:80"
             - ./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?

  • Connect from a Docker container to port of another docker container
  • Running Couchbase under GCE Docker and getting error about max number of files
  • Auth0 OWIN API not validating JWT token when published via Docker Container on AWS EC2
  • Vagrant, Docker, and Node.js on Mac OS X
  • Docker ps -a doesn't show a stopped mysql client running container
  • What does volume_from do if there are no volumes in the volume container?
  • 3 Solutions collect form web for “Making an API call from dockerized web page to back-end server ends up with net::ERR_CONNECTION_REFUSED”

    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.

    Try communicating to source docker via environment variables provided by docker. See this

    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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.