1

I have a very simple docker-compose.yml file where I use nginx and mounting a file as a volume.

But everytime I run the application, it is creating a directory .htpasswd without really mounting the .htpasswd file where I locally.

This is the docker-compose.yml.

version: '3'
services:

  reverse:
    container_name: reverse
    hostname: reverse
    restart: unless-stopped
    image: nginx
    ports:
      - 80:80
      - 443:443      
    volumes:
      - ./nginx/.htpasswd:/etc/nginx/conf.d/.htpasswd

Can someone help me fix this?

Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105
  • can you please add a file listing for the `./nginx/` directory? (like adding the output for `ls -l`) – Noam Yizraeli Mar 07 '22 at 20:35
  • I believe this answers your question - https://stackoverflow.com/questions/42248198/how-to-mount-a-single-file-in-a-volume – Walker Sutton Mar 07 '22 at 20:37
  • @NoamYizraeli: here is the output `-rw-r--r-- 1 jananath staff 43 7 Mar 23:43 .htpasswd ` – Jananath Banuka Mar 07 '22 at 20:37
  • please try as suggested using the absolute path or mount relatively like now but the entire host nginx directory to `conf.d` inside the container – Noam Yizraeli Mar 07 '22 at 20:42
  • @NoamYizraeli, mounting an almost empty dir to conf.d will likely override/remove a file called default.conf which is probably not desired. From my expierence it is possible to mount a single file so long as the path is correct. – The Fool Mar 07 '22 at 21:47

2 Answers2

0

by default if binded to a none existent path, docker will create a folder, the solution would be in your case to create the path before running your docker-compose

SCcagg5
  • 576
  • 3
  • 15
0

How are you running Docker? here's an answer ...

For Mac with Minikube/Hyperkit docker and Docker Compose

Since I'm not using Docker Desktop any longer, I've experienced numerous issues similar to "docker in docker (dind)" paradigm with minikube...

  1. mount minikube
  2. use absolute path

e.g., easiest way was to mount the exact home path...

minikube mount $HOME:/Users/<you>

... keeps running...

docker-compose.yaml

volumes:
      - /Users/<you>/path/to/file.yaml:/somedir/file.yaml
Michael Ramos
  • 5,523
  • 8
  • 36
  • 51