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.
I have a basic html file called index.html.
In that same folder I created a Dockerfile without extension.
In the Dockerfile I have :
FROM nginx
COPY . /usr/share/nginx/html
I then opened a terminal in the same directory as my html file and the Dockerfile
I entered: docker build -t my-website ./ (it built successfully from what I can tell)
Then I entered: docker run -d -p 80:80 my-website (it ran successfully from what I can tell)
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.)
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?
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 0.0.0.0:80->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
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:
If that works, then you can just type the following in that CLI:
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!
@timigun, @avbentem
Today I encountered the same hurdle as timugun! Avbentem, I expect something in the docker dashboard in column ‘Ports’ 8080:80/index.html instead of 8080:80, simply because in the nginx.conf contains the instruction: try_files $uri $uri/ /index.html; or do I not understand the concept? Or do miss something in the Dockerfile? Can’t add an extra screenshot of the Dockerfile, sorry!
It feels a bit odd each time manually add ~/index.html or ~/Dockerfile
Any suggestion is welcome!