Docker Community Forums

Share and learn in the Docker community.

Local host only shows Nginx welcome page

I am brand new to Docker. I cannot see my website on the local server - it just gives me a Nginx welcome page even though I am following the exact steps of my course and the Docker tutorial.

  1. I have a basic html file called index.html.
  2. In that same folder I created a Dockerfile without extension.
  3. In the Dockerfile I have :
    FROM nginx
    COPY . /usr/share/nginx/html
  4. I then opened a terminal in the same directory as my html file and the Dockerfile
  5. I entered: docker build -t my-website ./ (it built successfully from what I can tell)
  6. Then I entered: docker run -d -p 80:80 my-website (it ran successfully from what I can tell)
  7. Then I went to http://localhost. All I see is this:

Things I have tried:

  • Switching off my firewall
  • I have Windows 10 (apparently it won’t work on Windows 7)
  • Using my computer’s terminal rather than Git Bash
  • Making sure my Dockerfile has no extension

Please can you help me figure out how to see my website on the localserver?

I’d say this looks okay. But still it seems somehow your own index.html was not copied into the image when you created that image by running docker build -t my-website ./

Was that index.html file available at that time? Creating or changing it at a later time will not affect what you’re seeing once you copied it into an image and started a container using that image.

Aside, as you copied the full current folder into the image, the Dockerfile itself will be in the image too; you should be able to get that using http://localhost/Dockerfile

(To retry, you’ll first have to stop the container that is running in the background as a daemon. Something like docker ps will give you the container name, which you can use in docker stop <container-name>. When using docker run again you may want to specify a name for the container, using --name my-name. Or don’t use -d so you can stop by just hitting Ctrl+C.)

1 Like

Hi Avbentem, thanks so much for your response!

index.html was available at the time in the sense that it wasn’t open or even recently changed. It was just present in the same folder as the Dockerfile. Is there another way in which it might be unavailable at the time of building and running?

That said, after I successfully downloaded the Dockerfile by typing in http://localhost/Dockerfile, I tried typing in http://localhost/index.html. And that successfully displayed the index.html page on my browser.

Does this mean that I must simply always specify the index.html when I click localserver? If so, then I think I have my answer :slight_smile:

Hmmm, that is unexpected. When not explicitly asking for a specific file (like /index.html) then Nginx will return a default file which, I thought, would return index.html as well. So, using http://localhost I would expect to see your index.html, not some Nginx file.

To tell what is in your image, use docker ps to find the name of the running container and then run:

docker exec -it <container-name> ls -l /usr/share/nginx/html

When running the commands you showed in your first post, I get:

$ docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                NAMES
e12e725871b1   my-website   "/docker-entrypoint.…"   2 seconds ago   Up 2 seconds>80/tcp   sad_lamarr
$ docker exec -it sad_lamarr ls -l /usr/share/nginx/html
total 12
-rw-r--r-- 1 root root 494 Dec 15 13:59 50x.html
-rw-r--r-- 1 root root  40 May 24 19:10 Dockerfile
-rw-r--r-- 1 root root  10 May 24 19:10 index.html

What do you see?

1 Like

I see this:
$ docker exec -it cool_hermann ls -l /usr/share/nginx/html
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty’

I guess you used Git Bash for that? I’d indeed try to use:

winpty docker exec -it cool_hermann ls -l /usr/share/nginx/html

Alternatively, maybe Windows command prompt will work (without winpty), or PowerShell. Windows is not my strong suit.

Also, the Dashboard in Docker Desktop has an option to open a command line interface (CLI) for you, when you hover your mouse over an entry in Containers/Apps:

Docker Desktop

If that works, then you can just type the following in that CLI:

ls -l /usr/share/nginx/html
1 Like

Indeed I was using Git Bash. Instead I tried the regular command prompt and it works. Will check out the Docker Desktop command line interface too.

But before I entered the prompt you suggested, I checked the localhost one last time, and it was working! I don’t know how to explain it but after sleeping on it and trying again in the morning it now works and doesn’t give me the welcome screen anymore. I’m not sure what happened or changed but I tested with a different website and it works there too now.

I want to say thank you for you patience and advice, I really appreciate you taking the time!

1 Like