1

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:

  • Dockerfile

    FROM nginx:1.18.0
    
    WORKDIR /usr/share/nginx/html
    COPY index.html ./
    
  • index.html

    <!DOCTYPE html>
    <html>
        <head>
            <title>Testing</title>
        </head>
        <body>
            <p>Hello Test App</p>
        </body>
    </html>
    

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.