Search code examples
dockernginxvolumedocker-volume

How do i map a volume to replace the standard index.html of a nginx container


I'm trying to make a simple map of a volume inside an nginx container for study purposes. To make it i created an index.html like this:

<html>
  <head>
    <title>TEST</title>
  </head>
  <body>
    <h1>SOMETHING</h1>
    <p>Works!!</p>
  </body>
</html>

At the path in my PC (host):

c:/codes/test-docker/html/index.html

All i want to do is to have this index.html inside of my nginx container to replace the standard index.html of nginx.

I have tried to run the code:

docker run --name ng -p 80:80 -v /c/codes/test-docker/html:/usr/share/nginx/html nginx

It didn't returned me any errors, but when access port 80 to see if it really works, i still have the standard nginx standard index.html running.

My actual OS is Windows 10 Home at the version 10.0.19045 and i running all the codes in the git bash terminal.


Solution

  • Assuming you're using Linux Docker using WSL2, you use normal Windows file naming on the host side like this

    docker run --name ng -p 80:80 -v c:\codes\test-docker\html:/usr/share/nginx/html nginx