I am using the above link to follow steps to create custom HTML using NGINX. As mentioned in the tutorial I have created a index.html file in site-content folder in my local machine. After that when I execute the
$ docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx
command and check http://localhost:8080 I still get old message of Welcome to nginx. Could I please get help on this?
I don’t have “docker desktop for windows” available right now, so please wait for more details.
You can login to the container by typing the command “docker exec” in a terminal (powershell etc…) with the command “docker run”.
ubuntu@ubuntu:~$ docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx
ubuntu@ubuntu:~$ docker exec -it web bash
root@3f1ba1408e11:/# ls /usr/share/nginx/html
root@3f1ba1408e11:/# cat /usr/share/nginx/html/index.html
<h2>Hello from Nginx container</h2>
Unless you are running the command in a WSL distribution for which you enabled the WSL integration in Docker Desktop, ~ will not work. You can replace it with %USERPROFILE% if you run it from command line. I am not sure about the syntax in PowerShell, but I wouldn’t store the site-content in the user profile folder anyway. I would create a project folder and run the commands there so I could use $(pwd) which works on Linux, macOS and in PowerShell.
Or the best would be to create a compose file and just using relative path.
By the way I don’t recommend using -it and -d at the same time. Asking for an interactive terminal in a detached container doesn’t make sense and some processes like Apache HTTPD could stop just because you use docker attach. Or without -d, resizing an terminal window could stop the container. --rm is usually not used either with detached containers but in some cases it can still be useful. I know that all these flags were in the blog post, but that was probably a mistake . Sometimes I make that mistake too when I run multiple bash containers and suddenly I want to run a server.
Note: I fixed your posts. Please, always check your posts after sending them and make sure everything looks like as expected. Otherwise some parts of the message could disappear and nobody understands your question. The