I’m a newbie, and I recently installed Docker Desktop on my Windows 11 PC. Initally, I upgraded WSL to version 2, and that created a Linux instance as seen in Explorer under Network. Under Network > Linux I see docker-desktop and docker-destop-data folders. Then I installed Ubuntu-22.04 which is also now listed under Network > Linux > Ubuntu-22.04. I want to install the NGINX container and use a persistent host folder (C:\docker). I use the following command in PowerShell:
docker run -d -p 8080:80 -v C:\docker:/host_mnt/c/my-nginx --name mynginx nginx
If I open a bash shell with
docker exec -it mynginx /bin/bash
I can list the content of /host_mnt/c/my-nginx and I see the files in my host folder (C:\docker). However, when I browse to localhost:8080, I see only the default NGINX welcome screen. I don’t see my index.html file, and I get a 404 error if I try to browse to a second file test.html in my host C:\docker folder.
Been arm-wrestling this issue for days. Clearly I’m doing something wrong, but I’m stumped. I’ve tried using chatGPT, YouTube, and event purchased a Kindle book to discover the error of my ways, but it’s all been for naught. I even considered re-installing Docker in Ubuntu, but everything I’ve seen and read suggests that I should be able to accomplish running Docker in Windows.
You are missing an nginx configuration in /etc/nginx that actually configures nginx to use that folder.
Nginx won’t be able to pick up on your intent, you need to configure it properly to do what you want.
The image description should give the required hints: nginx.
Furthermore, you might want to look at the nginx beginner’s guide for instructions on how to create custom configurations.
Thanks meyay. It took me a bit more effort to accomplish my goal, and you pointed me in the right direction. I wound up building an nginx image and copying my content and default.conf files to the appropriate container folders. I’m not clear yet whether I could accomplish this without creating a custom image–I tried doing that but without success. I found an excellent video on YouTube by “Techno Tim” (Build YOUR OWN Dockerfile, Image, and Container - Docker Tutorial - YouTube) that finally turned on the light. Following are the details.
and voila! I browsed to localhost:8080 where I could see my HTML. So thanks again for heading me in the right direction. I know that you know all of this… I only include the details here in case someone else is faced with a similar issue and struggling with a solution.
Thank you for sharing your final result, so others that stumble across this topic also find the solution.
Minor note: you could have mounted the files into the container paths and would have had the same result without creating your own image. This appoach is ofthen used during development.
I missed out last time that the topic was created in the “Community” category, which is for either announcing community events or asking details about them. I moved your topic to “Genera Discussion/General” as it’s not relate
I forgot to include what I added to the default.conf file. The following lists the original default server configuration, which I commented out, and the http block that I added:
So then I created a container from the standard NGINX image (without first creating a custom image). Initially I thought I would need to mount both the host ‘content’ and the ‘conf’ folders to the container, but I only needed to mount the ‘content’ folder.
Here’s the run command that mounts the host folder where I can edit, add, and delete files and have the results available in the browser:
docker run -d -p 8085:80 --mount type=bind,source=C:\docker\content,target=/usr/share/nginx/html --name mynginx nginx
I’m using host port 8085 so the nginx server doesn’t conflict with my other server running on this PC.
This entire effort has been a kind of trial to get my feet wet with Docker with an aim to deploy an mssql-server container. Previously I was able to deploy the mssql-server, but I was unable to connect on the host PC. I think part of the problem was trying to use a non-standard port other than 1433. So this is the next task.
Unlinke in you original post, this time you mounted the host folder into the expected target folder inside the container (the one mentioned in the dockerhub description). Of course, you don’t have to mount your modified conf in that scenario.
Though whenever you need to use a specific nginx configuration – using another path for the root of the / location would be such a scenario - you’ll need to create it and mount it into the container.