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?
Yes I have stopped the container once. Also i checked the files. I am using docker desktop and command prompt to execute the commands. After I stopped the container and run next command
docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx
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â.
Sample:
ubuntu@ubuntu:~$ docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx
3f1ba1408e1140c153a3f2fc19c815ccb4ee0437a064beb0dc9afc768b411a26
ubuntu@ubuntu:~$ docker exec -it web bash
root@3f1ba1408e11:/# ls /usr/share/nginx/html
index.html
root@3f1ba1408e11:/# cat /usr/share/nginx/html/index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Docker Nginx</title>
</head>
<body>
<h2>Hello from Nginx container</h2>
</body>
</html>
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