
Question:
I'm trying to run nginx within a docker container whilst mounting the configuration and static html files for it to serve up. Very simple stuff as far as I'm aware, but I keep getting an error about the directory not being a directory?
I'm running this example on my Mac using the latest version of Boot2Docker.
I have the following folder structure:
% tree ~/Projects/Docker/nginx-example
.
├── html
│ └── test.html
└── nginx.conf
1 directory, 2 files
The contents of the nginx.conf
is as follows:
http {
server {
listen *:80; # Listen for incoming connections from any interface on port 80
server_name ""; # Don't worry if "Host" HTTP Header is empty or not set
root /usr/share/nginx/html; # serve static files from here
}
}
I try to run the container (from within the ~/Projects/Docker/nginx-example
directory) like so:
docker run --name nginx-container \
-v /Users/M/Projects/Docker/nginx-example/html:/usr/share/nginx/html:ro \
-v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx:ro \
-P -d nginx
<blockquote>
Originally I had tried something like -v $(pwd)/html:/usr/share/nginx/html:ro
to keep the command shorter, but when it didn't work I thought I'd be explicit just in case there was some funky sub shell issue I wasn't aware of
And I get the following output
fc41205914098d236893a3b4e20fa89703567c666ec1ff29f123215dfbef7163
Error response from daemon:
Cannot start container fc41205914098d236893a3b4e20fa89703567c666ec1ff29f123215dfbef7163:
[8] System error: not a directory
Does anyone have any idea of what I'm missing?
<h2>Mac Boot2Docker Volume issue?</h2>I'm aware there is an issue with mounting volumes into containers when using Boot2Docker (although I'm led to believe this has long been resolved)
i.e. <a href="https://stackoverflow.com/questions/26348353/mount-volume-to-docker-image-on-osx/27540955#27540955" rel="nofollow">Mount volume to Docker image on OSX</a>
But I followed the instructions there regardless, and it still didn't work
Answer1:-v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx:ro
you are attempting to mount a file to a directory - change that to:
-v /Users/M/Projects/Docker/nginx-example/nginx.conf:/etc/nginx/nginx.conf:ro
and you should be fine. Take a look at the examples in the <a href="https://docs.docker.com/userguide/dockervolumes/" rel="nofollow">Docker Volumes Docs</a>
As well, pwd
should work in the path. The shell expands this before the docker command is run, just like math and inner parenthesis, inner sub-commands are run first.