为什么我会收到错误 "You don't have permission to access / on this server."?

Why do I get the error "You don't have permission to access / on this server."?

我尝试 运行 我的网站 docker 这是我的 docker-compose.yml:

version: '2'
services:
  php:
    image: yiisoftware/yii2-php:7.1-apache
  volumes:
    - ~/projects/my-project-name.local/composer- 
    docker/cache:/root/.composer/cache:delegated
    - ./:/app:delegated
  ports:
    - '8000:80'

当我运行"docker-compose up -d --build"打开一个urllocalhost:8000时出现错误"Forbidden.You don't have permission to access / on this server." 容器的日志是:

AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.22.0.2. Set the 'ServerName' directive globally to suppress this message
AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.22.0.2. Set the 'ServerName' directive globally to suppress this message
[Tue Jul 10 06:42:22.442648 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Tue Jul 10 06:42:22.442713 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Tue Jul 10 06:42:25.985025 2018] [core:error] [pid 17] [client 172.22.0.1:48650] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html
172.22.0.1 - - [10/Jul/2018:06:42:25 +0000] "GET / HTTP/1.1" 403 503 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
[Tue Jul 10 06:42:26.117774 2018] [core:error] [pid 17] [client 172.22.0.1:48650] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html, referer: http://localhost:8000/
172.22.0.1 - - [10/Jul/2018:06:42:26 +0000] "GET /favicon.ico HTTP/1.1" 403 513 "http://localhost:8000/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"

当我将相同的 docker-compose.yml 与 yii2 basic 一起使用时,一切正常。 请帮我解决这个问题。我的 OS 是 Ubuntu-18.04。

yii2 docker 镜像基于 php 镜像,在其 Dockerfile 中包含以下行:

# Copy the app code into the image
COPY . /var/www/html

这与日志中的警告一致。

当你将它添加到你的 Dockerfile 时,你应该没问题(假设你的源代码在当前目录中)。

如果您想使用 docker 容器作为开发环境,您可以将源代码文件夹挂载到 /var/www/html。在这种情况下,您必须添加一个卷:

volumes:
  - .:/var/www/html # Add this line