Static web application in docker using nginx - localhost refused to connect

402 views Asked by At

enter image description hereDocker file contains the following command

FROM nginx
COPY . /usr/share/nginx/html

To build my docker image i have used following command

docker build -t <tagName>/img .

To run the docker image

docker run -p 80:8080 <tagName>/img

But i am not able to lanch my static site in my browser . i am getting

This site can’t be reached
localhost refused to connect.

enter image description here

2

There are 2 answers

0
Kimi Marie On

You are mapping port 80 to 8080 here: docker run -p 80:8080 <tagName>/img, so to access your app just use the address: 'localhost:80' (or you can ommit the port since 80 is the default port used in browsers)

1
boppy On

While Kimi Marie is totally correct, the nginx Dockerfile provides port 80 inside the container. So I assume you would like to map the container's port 80 to your local port 8080. You just need to flip the params like

docker run -p 8080:80 <tagName>/img