0

I would like to run NGINX in Docker and serve some files, but I am not able to do it this way:

docker run --rm --name some-nginx -p 10088:80 -v mydir:/usr/share/nginx/html:ro nginx

I am able to see http://localhost:10088 but if I try to access any file in mydir/, it fails. For example http://localhost:10088/README.md gives this result:

2020/01/21 07:10:20 [error] 6#6: *1 open() "/usr/share/nginx/html/README.md" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /README.md HTTP/1.1", host: "localhost:10088"
172.17.0.1 - - [21/Jan/2020:07:10:20 +0000] "GET /README.md HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"

Any idea how to setup nginx easily?

Note: I don't want to create new image as suggested at https://hub.docker.com/_/nginx, I want to use volume.

Note 2: I've just noticed (after attach to the nginx container):

root@a2813aa84991:/usr/share/nginx/html# ls
50x.html  index.html

It seems volume mydir/ is not mounted.

Michal Špondr
  • 1,337
  • 2
  • 21
  • 44
  • Does this answer your question? [Docker Volume not mounting any files](https://stackoverflow.com/questions/34504156/docker-volume-not-mounting-any-files) – Mike Doe Jan 21 '20 at 07:21
  • @emix Not really, but the problem is similar: I need to use absolute path instead of relative. – Michal Špondr Jan 21 '20 at 07:24
  • 1
    Since you have mounted your container using `name:/path` syntax, Docker created a volume for you, named `mydir`. You can verify that using `docker volume ls` – Mike Doe Jan 21 '20 at 08:13

1 Answers1

0

I have to mount volume with absolute path:

docker run --rm --name some-nginx -p 10088:80 -v $(pwd)/repository:/usr/share/nginx/html:ro nginx

This works.

Michal Špondr
  • 1,337
  • 2
  • 21
  • 44