4

Files tree:

├── docker-compose.yml 
├── Dockerfile 
└── www 
    └── index.html

Dockerfile :

FROM php:5.6-apache
ADD ./www /var/www/html/
WORKDIR /var/www/html/

docker-compose.yml

version: '2'
services:
  php5_6:
    build: .
    ports :
     - "80:80"
    volumes:
     - ./www:/var/www/html/

Try to start docker

$ docker-compose up
[core:error] [pid 17] (13)Permission denied: [client 172.19.0.1:53514] AH00035: access to /index.html denied (filesystem path '/var/www/html/index.html') because search permissions are missing on a component of the path

In browser http://localhost 403 page

What's wrong?

ZxDx
  • 51
  • 1
  • 4

3 Answers3

4

I know my answer is late, but someone else will get some help from this answer.

Use :z or :Z option at the end to mount your volume with enough permissions. To be exact this will add a selinux rule chcon -Rt svirt_sandbox_file_t /path/to/volume

version: '2'
services:
php7_2:
  build: .
  ports :
   - "80:80"
  volumes:
   - "./www:/var/www/html/:Z"

Read more details at,

  1. http://www.projectatomic.io/blog/2015/06/using-volumes-with-docker-can-cause-problems-with-selinux/
  2. Permission denied on accessing host directory in docker
PraAnj
  • 899
  • 1
  • 10
  • 27
0

The error message is indicating that apache doesn't have the appropriate access to the html directory. In particular it likely needs execute permission in addition to read permissions.

Try adding RUN chmod -R 755 /var/www/html/ to your Dockerfile.

Kenan
  • 3,560
  • 1
  • 18
  • 7
0

The problem is enabled SELinux. Disable in /etc/selinux/conf will solve it.