connection refused from upstream html - NGINX

br flag

I have an html file running on a docker container with this url: http://localhost:80 I want to redirect this to another port like http://localhost:8080 with NGINX. I have the following config for it:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/;

events {
    worker_connections  1024;

http {
    include mime.types;
    sendfile on;
    upstream web {


    server {
    listen       8080;
    autoindex off;
    server_name _;
    server_tokens off;

    location / {
        proxy_pass http://web;

but when I go to http://localhost:8080, I get 502 bad gateway error and here is the error I get through nginx container:

[error] 22#22: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server: _, request: "GET / HTTP/1.1", upstream: "", host: "localhost:8080"

This is how I start my nginx docker:

docker run --name nginx -v c:/Users/ds-nginx-conf-main:/etc/nginx -p 8080:8080 -d nginx

here is the docker compose file of web container or the pre exciting container:

version: "3.7"

        build: ui
          - 80:80
          - api
        build: app
          - PORT=80
          - 8020:80
          context: ./
          dockerfile: ./test/Dockerfile
in flag

Processes inside a docker container run inside their own namespace.

Every container has its own virtual loopback interface, which is separate from the loopback interface of the host.

If you want to access another container from inside a container you need to link these containers together.

docker run --link othercontainer ...

Then you can access the first container from the second container by its name.

Other options are to create a network inside docker which is used by both containers, or have both containers use the host network (which is usually discouraged because it increases the attack surface of the container).

CFD avatar
br flag
I tried to do that but I receive this error: $ docker run --link ds-ai-ocr-main_web_1 --name nginx -v c:/Users/ds-nginx-conf-main:/etc/nginx -p 8080:8080 -d nginx 81c9e792ee939c82e86454252d97dd46b0554fa6b244037fabb842898abd5d36 docker: Error response from daemon: Cannot link to /ds-ai-ocr-main_web_1, as it does not belong to the default network.
in flag
That looks like your first container was created with docker-compose. Then you need to reconfigure your first container to utilize am external network that can be shared with your second container.
CFD avatar
br flag
I added the docker compose to the question. I am trying to add this to the docker compose but I recieve error: `networks: default: external: true`

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.