-4

docker run command error: (I was knocking on the document command, Docker version 18.03.0-ce), ask why?

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

The error is as follows:

ebb97ea2c176cb1693912f54960db6281b30c95482c67df37183a8e1c618ca92
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/home/xiao/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged\\\" at \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: 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.
jrtapsell
  • 6,719
  • 1
  • 26
  • 49

1 Answers1

0

Problem is due to $PWD/conf/nginx.conf exists in your container, and command docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf ... is trying to replace nginx.conf in your container with nginx.conf from your host.

If you want to have a nginx server in your container with your host's nginx.conf configuration, you have to assure yourself that nginx.conf doesn't exist in container. If it exists in containers because you're installing it in Dockerfile and you want to keep in container your host nginx.conf file anyway, you need add RUN rm -f $PWD/conf/nginx.conf to your container Dockerfile after nginx installation.

Note that I'm only showing you a possible solution for your proposal, but I cannot recommend you to do it until I know why do you need to use your nginx.conf into the file.

Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42