This article assumes an environment where Docker works.
Quickly check the local HTML file with a browser.
When you are given a rough HTML file like "This HTML doesn't work for some reason, can you check it?", If you open the browser as it is, you may have trouble reading the external file, right?
A long time ago, I used to launch XAMP and MAMP, and use OS standard sharing services. The publishing procedure is a bit cumbersome, and I often forget to stop publishing and continue to use extra resources.
With the birth of Docker, there is an easy way to check local HTML files without polluting the OS as much as possible.
Start the server locally and temporarily publish the directory containing the HTML files.
Go to the HTML file directory in the console
docker run -v $(pwd):/usr/share/nginx/html:ro --rm -p 8080:80 nginx
If this is the only file name test.html http://127.0.0.1:8080/test.html You will be able to access the file with.
You can see the communication log because it is not started as a daemon without the -d option, and when you stop the Ctrl + C process, the container disappears with --rm, so it is clean. Since you don't have to name the container with --name, the command is short and easy to remember.
For those who only accept Apache for religious reasons
docker run -v $(pwd):/usr/local/apache2/htdocs/:ro --rm -p 8080:80 httpd
Please start up with.
If $ (pwd) doesn't work or you don't understand the meaning, please specify the directory path you want to publish as follows.
docker run -v /Users/qiita/Downloads:/usr/share/nginx/html:ro --rm -p 8080:80 nginx
I wrote a similar article in the past, but I realized that I should use the --rm option to clean up after finishing without having to make it a daemon separately, so I wrote it again.
Previous article https://qiita.com/rspepe/items/6f7f5eb31a04185bafbd
Recommended Posts