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
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?
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. Mount volume to Docker image on OSX
But I followed the instructions there regardless, and it still didn't work
A Docker volume is a directory somewhere in your Docker storage directory and can be mounted to one or many containers. They are fully managed and do not depend on certain operating system specifics. Before removing the Docker volume, you can open your Docker GUI and inspect the volume by clicking on the data tab.
If nginx is running in a container then your site is going to be 100% dead to the world while Docker isn't running. Users will get a connection error. When nginx is installed directly on your host you can serve a 503 maintenance page that doesn't depend on Docker or any containers running.
The VOLUME command will mount a directory inside your container and store any files created or edited inside that directory on your hosts disk outside the container file structure, bypassing the union file system.
-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 Docker Volumes Docs
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With