Docker 和 symfony

Docker and symfony

我正在努力 Docker。

我正在尝试创建一个图像来处理 symfony 项目并同时学习 Docker。 这是我的 Docker 文件:

FROM php:7-apache

LABEL Description = "This image is used to start Symfony3 project"

ENV DIRPATH /var/www/html

# apt-get command
RUN apt-get update && apt-get install -y \
    vim \
    git \
 && apt-get clean

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer

# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony

我用命令构建镜像:

docker build -t symfony .

效果很好!酷!

我正在创建一个容器:

docker run --name symfony -d -v "$PWD":/var/www/html -p 80:80 symfony

效果也很好。 Web 服务器 运行 在正常端口上。

我可以放入我的容器中:

docker exec -ti symfony bash

但是当我尝试进行作曲家更新时,我遇到了一些错误:

Failed to download symfony/symfony from dist: Could not decompress the archive, enable the PHP zip extension.
A php.ini file does not exist. You will have to create one.

如何在 Docker 文件中创建 php.ini?

我也认为我的权限有问题。 当我尝试 web/app_dev.php 时,我收到此消息:

You are not allowed to access this file. Check app_dev.php for more information.

您可以添加自定义 php.ini 配置,在 dockerfile 中指定它, 作为示例,您可以查看此示例的 this repo

dokerfile

# install a few more PHP extensions
RUN apt-get update && apt-get install -y php5-imagick php5-gd php5-mongo php5-curl php5-mcrypt php5-intl

# copy a custom config file from the directory where this Dockerfile resides to the image
COPY php.ini /etc/php5/fpm/php.ini

您可以在网上找到各种方法和各种示例。

希望对您有所帮助

在丢失的 php.ini 文件旁边,您还应该安装 zip,以便您可以从 dist 下载,即

RUN docker-php-ext-install zip

这将安装并启用错误消息中要求的 PHP zip 扩展。