'How to connect external files to docker-nginx container?

I read almost all threads under volume but I am still not able to solve my issue.

  • I have a nginx image in my docker. When I do docker images this is what I get:
xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website
$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    ae2feff98a0c   5 days ago   133MB

In my current directory desktop/website I have a file called index.html which I want to map inside the usr/share/nginx/html docker container. For that I type a command :

xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website
$ docker run --name website -v $(pwd):/usr/share/nginx/html -d -p 8080:80 nginx

The command runs fine and I get some random numbers like

xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website
$ docker run --name website -v $(pwd):/usr/share/nginx/html -d -p 8080:80 nginx
29630977004cb59b3f4b67ea99f5bb28e3434c02c4c62d4cb20c4b1ccd82fafc

xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website

But when I do localhost:8080, I get the same old message "welcome to Nginx."

I tried going inside the container(usr/share/nginx/html) to see if changes have made with the command

xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website
$ docker exec -i website bash

I found nothing is changed. The files are still the same. (I don't know if it is supposed to be changed)

How to do this. Is there an alternative. I am using git bash and I am on windows machine.



Solution 1:[1]

Apparently it is an issue with git-bash that doesn't recognize ($pwd). Try using one of these ways:

docker run --name website -v /$PWD:/usr/share/nginx/html -d -p 8080:80 nginx

docker run --name website -v "$PWD":/usr/share/nginx/html -d -p 8080:80 nginx

docker run --name website -v /c/some/some:/usr/share/nginx/html -d -p 8080:80 nginx

docker run --name website -v C:\\some\\path:/usr/share/nginx/html -d -p 8080:80 nginx

Sorry, I have no Windows here to try this out. Hope that works as expected.

Solution 2:[2]

This might be coming late, but hopefully it could help someone else just getting into Docker on a Windows machine, it would be

xxxxxx@DESKTOP-7904JF2 MINGW64 ~/desktop/website
$ docker run --name website -v ${pwd}:/usr/share/nginx/html -d -p 8080:80 nginx

your 'pwd' should be wrapped in curly braces instead this should be run from Powershell

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bruno Criado
Solution 2