0

I got this task at the university to run an nginx docker on the virtual machine and mount the /etc/nginx/ directory to the 'pwd'/webconfig, but I don't know how to solve. I tried this:

docker run -p 80:80 -v 'pwd'/webconfig/:/etc/nginx/ --name websrv -d nginx

but I got this error message at the docker logs

[emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory) nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

After this I tried to mount the nginx.conf too:

docker run -p 80:80 -v 'pwd'/webconfig/nginx.conf/:/etc/nginx/nginx.conf/ -v 'pwd'/webconfig/:/etc/nginx/ --name websrv -d nginx

And then I got this error message in the logs:

[crit] 1#1: pread() "/etc/nginx/nginx.conf" failed (21: Is a directory) nginx: [crit] pread() "/etc/nginx/nginx.conf" failed (21: Is a directory)

This is the point where I cannot step forward.

  • I see you can refer to https://stackoverflow.com/questions/41485217/mount-current-directory-as-a-volume-in-docker-on-windows-10 – Tien Nguyen May 19 '21 at 07:18

3 Answers3

0

Please make sure you use the right folder to take the nginx.conf file from.

'pwd' usually refers to the current directory. If you run pwd in your terminal you will see the current folder you are in. take that folder and add the /webconfig to get your complete current directory. You'll probably get something like /usr/username/home/webconfig/

You can use that folder to mount your docker volumes, and your command should become something like this:

docker run -p 80:80 -v '/usr/username/home/webconfig/:/etc/nginx/ --name websrv -d nginx
Thijs
  • 26
  • 4
0

Try this:

docker run -p 80:80 -v $PWD/webconfig:/etc/nginx/ --name websrv -d nginx
Kapil Khandelwal
  • 1,096
  • 12
  • 19
-1

You can use VOLUME command to mount a volume from host system to docker container. Apart from that you also have COPY command to upload a already created config file.

  • The `VOLUME` directive doesn't specify anything about host-system content. There's rarely a reason to use it at all. – David Maze Apr 08 '20 at 11:10
  • @DavidMaze actually I thought user wanted to mount an entire directory to container from host system. Docker documentation has assembled this scenario nicely https://docs.docker.com/storage/bind-mount/ – user13257160 Apr 09 '20 at 09:21