如何配置Docker DOCROOT以运行symfony

时间:2019-12-30 11:02:46

标签: php docker symfony docker-compose

我使用docker-compose设置了一个php docker容器,工作正常,现在我试图在其中安装symfony。在我的docker-compose.yml中,我有:

version: "3"

  services:
    webserver:
      build:
        context: ./bin/webserver
      container_name: '7.4.x-webserver'
      restart: 'always'
      ports:
        - "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
        - "${HOST_MACHINE_SECURE_HOST_PORT}:443"
      links:
        - mysql
      volumes:
        - ${DOCUMENT_ROOT-./www}:/var/www/html
        - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
        - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
        - ${LOG_DIR-./logs/apache2}:/var/log/apache2

当我运行docker-compose up -d时,将包含symfony的本地www文件夹的内容复制到/ var / www / html中的容器中,这很好。

问题是symfony的文档根目录必须指向www内的“ public”文件夹,并且应位于容器中的/ var / www / html内。我该如何设置?

1 个答案:

答案 0 :(得分:-3)

我这里有使用Docker Compose的PHP LAMP堆栈https://github.com/delboy1978uk/lamp

我使用自定义的Apache Dockerfile和virtualhosts配置:

awesome.scot:
    build: ./build/httpd
    links:
        - php
    ports:
        - 80:80
        - 443:443
    volumes_from:
        - app

请注意,我有一个单独的容器用于实际安装,称为应用程序,它仅使用默认的Apache映像:

app:
    image: httpd:2.4.38
    volumes:
        - ./:/var/www/html
    command: "echo true"

在build / httpd / DockerFile中,我告诉它复制我的虚拟主机配置

COPY ./httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf

并且说配置已经定义了公用文件夹:

<VirtualHost *:443>
    ServerName awesome.scot
    ServerAlias localhost
    ServerAdmin delboy1978uk@gmail.com
    DocumentRoot /var/www/html/public

    SSLEngine on
    SSLCertificateKeyFile /etc/ssl/certs/selfsigned.key
    SSLCertificateFile /etc/ssl/certs/selfsigned.crt

    <Directory "/var/www/html">
            DirectoryIndex index.php
            FallbackResource /index.php
            Options -Indexes +FollowSymLinks
            AllowOverride FileInfo All
            Require all granted
    </Directory>
    ProxyPassMatch ^/(.*\.php)$ fcgi://php:9000/var/www/html/public/$1
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</VirtualHost>

<VirtualHost *:80>
    ServerName awesome.scot
    ServerAlias localhost
    DocumentRoot /var/www/html/public

    <Directory "/var/www/html">
            DirectoryIndex index.php
            FallbackResource /index.php
            Options -Indexes +FollowSymLinks
            AllowOverride FileInfo All
            Require all granted
    </Directory>
    ProxyPassMatch ^/(.*\.php)$ fcgi://php:9000/var/www/html/public/$1
</VirtualHost>