Vaccano
Vaccano

Reputation: 82341

Basic Nginx container (static file)

I am trying to do the simplest possible container with Nginx hosting a simple index.html file. But I can't seem to get it working. I must be missing a concept somewhere and I am hoping for a bit of help. Here is what I am doing:

I have a folder with 2 files in it:

First I build the container. From the folder that has the files, I run this command:

docker image build --tag nginx-test:1.0.0 --file ./Dockerfile .

Then I run the container:

docker run -d -p 3737:3737 nginx-test:1.0.0

Then I browse to http://localhost:3737 (I also tried http://localhost:3737/index.html) and chrome shows an ERR_EMPTY_RESPONSE error:

ERR_EMPTY_RESPONSE

How can I get my index.html file to be hosted in my container?

Upvotes: 1

Views: 533

Answers (1)

Vaccano
Vaccano

Reputation: 82341

The problem was with this command:

docker run -d -p 3737:3737 nginx-test:1.0.0

The -p option is selecting the ports. The first port is what will be exposed on the host machine. The second port is what will be used to communicate with the container. By default, nginx uses port 80 (like most web servers).

So changing that command to:

docker run -d -p 3737:80 nginx-test:1.0.0

Causes the rest of the steps in my scenario to work correctly.

Upvotes: 1

Related Questions