Whenever you try to map a single file into a container you might get a directory instead. Generally, this happens because of a host path being probably not valid or absolute. So, here’s the catch.
Prerequisites
- Docker
Solution
Example mapping a Nginx config under /etc/nginx/conf.d/
directory in a Docker Nginx container:
docker run -d -p 80:80 ${PWD}/nginx/devcoops.com.conf:/etc/nginx/conf.d/devcoops.com.conf --name nginx nginx
or:
docker run -d -p 80:80 /Users/devcoops/repos/devcoops.com/nginx/devcoops.com.conf:/etc/nginx/conf.d/devcoops.com.conf --name nginx nginx
A Docker Compose example:
...
volumes:
- ${PWD}/nginx/devcoops.com.conf:/etc/nginx/conf.d/devcoops.com.conf
or even:
...
volumes:
- /Users/devcoops/repos/devcoops.com/nginx/devcoops.com.conf:/etc/nginx/conf.d/devcoops.com.conf
Conclusion
In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.