I have an error that I can't resolve, even with my last researches.

Folder structure:

-rw-r--r-- 1 root root   105 Aug  8 15:58 Dockerfile
-rw-r--r-- 1 root root 21371 Aug  8 16:05 my-httpd.conf
drwxr-xr-x 2 root root  4096 Aug  8 15:37 www

1 - I create an image of apache with a simple Dockerfile


FROM httpd:2.4
WORKDIR /usr/local/apache2/htdocs
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf


docker build -t apache .

2 - I run a container with the new image


docker run -v /MY_PATH/www/:/usr/local/apache2/htdocs/ -dit --name apache -p 80:80 apache

3 - I want to protect access of the www folder, with htaccess

Folder structure:

-rwxr-xr-x 1 root root  116 Aug  8 15:37 .htaccess
-rw-r--r-- 1 root root   46 Aug  8 15:34 .htpasswd
-rwxrwxrwx 1 root root  169 Aug  7 10:52 index.html
-rw-r--r-- 1 root root  354 Aug  7 10:56 master.css
-rw-r--r-- 1 root root   26 Aug  7 10:57 robots.txt


AuthType Basic
AuthName "Restricted Area"
AuthUserFile /MY_PATH/www/.htpasswd
Require valid-user

4 - I try to access the index.html on my browser

The connexion windows appears, I type my login, and password.

Then I have a 500 Internal Server Error

5 - Logs said that "Could not open password file"

When I check the apache container logs, I have this:

[Fri Aug 09 07:19:58.458778 2019] [authn_file:error] [pid 7:tid 140331369154304] (2)No such file or directory: [client] AH01620: Could not open password file: /MY_PATH/www/.htpasswd - user [09/Aug/2019:07:19:58 +0000] "GET / HTTP/1.1" 500 528
[Fri Aug 09 07:19:58.534805 2019] [authn_file:error] [pid 7:tid 140331135788800] (2)No such file or directory: [client] AH01620: Could not open password file: /MY_PATH/www/.htpasswd, referer: http://mywebsite.com/

6 - I need your help :)

I search many times on Google, the only thing I found is about "SELinux", like this: Permission denied: Could not open password file.

I'm not sure that is the same here with the use of Docker.

So if someone can help me, it would be great! :)


The Apache in the container does not know about your external path /MY_PATH/www/, you need to use the path inside the container:

AuthUserFile /usr/local/apache2/htdocs/.htpasswd
  • Oh damn that was it. I'm ashamed :') Thank you! – mangasource Aug 9 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.