Are you trying to mount a directory onto a file &#

2019-01-26 03:56发布

问题:

I have a docker with version 17.06.0-ce. When I trying to install nginx using docker with command:

docker run -p 80:80 -p 8080:8080 --name nginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx:latest

it shows that

docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/appdata/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/dcea22444e9ffda114593b18fc8b574adfada06947385aedc2ac09f199188fa0\\\" at \\\"/var/lib/docker/aufs/mnt/dcea22444e9ffda114593b18fc8b574adfada06947385aedc2ac09f199188fa0/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

If do not mount the nginx.conf file, everything is okay. So, how can I mount the configuration file?

Thanks.

回答1:

Because docker recognize $PWD/conf/nginx.conf as folder and not file.
Check if $PWD/conf/ directory does not contain nginx.conf as directory.

Try with

> cat $PWD/conf/nginx.conf 
cat: nginx.conf/: Is a directory

Otherwise, open a Docker issue.
It's working fine for me with same configuration.



回答2:

If you are using Docker for Windows, this error can happen if you have recently changed your password.

How to fix:

  1. First make sure to delete the broken container's volume
    docker rm -v <container_name>
  2. Open Docker Settings
  3. Go to the "Shared Drives" tab
  4. Click on the "Reset Credentials..." link on the bottom of the window
  5. Re-Share the drives you want to use with Docker
    • You should be prompted to enter your username/password
  6. Click "Apply"
  7. Go to the "Reset" tab
  8. Click "Restart Docker"
  9. Re-create your containers/volumes

Credit goes to BaranOrnarli on GitHub for the solution.



回答3:

Remove the volumes associated with the container. Find the container name using docker ps -a then remove the container using:

docker rm -v <container_name>

Problem:

The error you are facing might occur if you tried running docker run command previously when file was not present at the location where it should have been in host directory. In this case docker daemon would have created a directory inside container in its place. Which later fails to map to proper file when correct files are put in host directory and docker is run again.

Solution:

Remove the volumes that are associated to the container. If you are not concerned about other container volumes, you can also use:

docker volume rm $(docker volume ls -q)


回答4:

could you please use the absolute path/complete path instead $PWD/conf/nginx.conf .it will work

EX:docker run --name nginx-container5 --rm  -v /home/sree/html/nginx.conf:/etc/nginx/nginx.conf -d -p 90:80 nginx
b9ead15988a93bf8593c013b6c27294d38a2a40f4ac75b1c1ee362de4723765b

root@sree-VirtualBox:/home/sree/html# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
b9ead15988a9        nginx               "nginx -g 'daemon of…"   7 seconds ago       Up 6 seconds        0.0.0.0:90->80/tcp   nginx-container5
e2b195a691a4        nginx               "/bin/bash"              16 minutes ago      Up 16 minutes       0.0.0.0:80->80/tcp   test-nginx


回答5:

i know this question was posted long ago
but still i would like to answer how i resolved this issue

i am using Docker ToolBox for windows.
by default C Drive is mounted automatically . so in order to mount the files, make sure your files and folders are inside C DRIVE
example:
C:\Users\%USERNAME%\Desktop



标签: docker nginx