Docker中的PhalconPHP

时间:2018-08-16 22:26:10

标签: docker phalcon

我正在使用本地计算机(mac)上安装的PhalconPHP构建一个Docker容器,如下所示:

FROM php:7.2-apache

...

RUN git clone --depth=1 git://github.com/phalcon/cphalcon.git /cphalcon
WORKDIR /cphalcon/build
RUN ./install
RUN touch /usr/local/etc/php/conf.d/docker-php-ext-phalcon.ini \
    && echo "extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so" >> /usr/local/etc/php/conf.d/docker-php-ext-phalcon.ini

...

然后我使用以下方法构建它:

docker build -t {registry url}/images/php72/apache/mongo:phalcon-dev -f {filename} .

构建完成后,我便可以使用docker-compose部署到本地计算机,并且运行良好。

然后我将其推送到我在GitLab上托管的私有Docker注册表中,如下所示:

docker push {registry uri}/images/php72/apache/mongo:phalcon-dev

但是当我将其拉到我的登台服务器(cent)并像这样使用docker-compose部署它时:

docker pull {registry uri}/images/php72/apache/mongo:phalcon-dev

容器的行为就像丢失了Phalcon一样。

我可以命令行进入容器并使用Dockerfile中的命令重建Phalcon,一切都会正常进行。

我在构建,推入或拉动命令中缺少什么吗?

感谢您的帮助!

文件:

Dockerfile

FROM php:7.2-apache

RUN apt-get update && apt-get install -y \
        libssl-dev \
        unzip \
        git

RUN apt-get install -y curl gnupg make g++ \
        && curl -sL https://deb.nodesource.com/setup_8.x | bash - \
        && apt-get install -y nodejs

RUN pecl install mongodb
RUN touch /usr/local/etc/php/conf.d/docker-php-ext-mongo.ini \
    && echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/docker-php-ext-mongo.ini

RUN git clone --depth=1 git://github.com/phalcon/cphalcon.git /cphalcon
WORKDIR /cphalcon/build
RUN ./install
RUN touch /usr/local/etc/php/conf.d/docker-php-ext-phalcon.ini \
    && echo "extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so" >> /usr/local/etc/php/conf.d/docker-php-ext-phalcon.ini

RUN a2enmod rewrite

RUN echo "\n \
<Directory /var/www/html>\n \
    RewriteEngine on\n \
    RewriteCond %{REQUEST_FILENAME} !-d\n \
    RewriteCond %{REQUEST_FILENAME} !-f\n \
    RewriteRule ^(.*)$ index.php?_url=/\$1 [QSA,L]\n \
</Directory>\n \
" >> /etc/apache2/apache2.conf

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
    && php composer-setup.php \
    && mv composer.phar /usr/local/bin/composer \
    && php -r "unlink('composer-setup.php');"

RUN apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && apt-get purge -y --auto-remove

WORKDIR /var/www/html

Docker-Compose文件:

version: "3"

networks:
    proxy:
        external: true
    site:
        external: true

services:
    db:
        container_name: {container name}
        environment:
            - MONGODB_ROOT_PASSWORD={password}
            - MONGODB_DATABASE={database}
        image: bitnami/mongodb:latest
        networks:
            - site
        restart: "always"
        volumes:
            - ./db:/bitnami/mongodb
    www:
        container_name: {container name}
        environment:
            - VIRTUAL_HOST={hostname}
            - VIRTUAL_PORT=80
        image: {registry name}/images/php72/apache/mongo:phalcon-dev
        networks:
            - site
            - proxy
        restart: "always"
        volumes:
            - ./www:/var/www/html

1 个答案:

答案 0 :(得分:0)

我也将Phalcon与docker一起使用,我的docker镜像基于Debian 9,但是运行良好。

查看我的dockerfile:

FROM debian:9

RUN apt-get update

RUN apt-get install -y \ 
    apt-transport-https \ 
    lsb-release \ 
    ca-certificates \ 
    wget \ 
    curl \ 
    nano \ 
    dialog \ 
    net-tools \ 
    openssl

RUN apt-get install -y nginx

RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
RUN apt-get update && apt-get install -y \
    php7.1 \
    php7.1-cli \
    php7.1-fpm \
    php7.1-mysql \
    php7.1-curl \
    php7.1-mbstring \
    php7.1-gettext \
    php7.1-gd \
    php7.1-fileinfo \
    php7.1-json \
    php7.1-mcrypt \
    php7.1-redis \
    php7.1-intl \
    php7.1-xml \
    php7.1-zip

RUN curl -s "https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh" | bash
RUN apt-get install -y php7.1-phalcon

ADD entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod a+x /usr/bin/entrypoint.sh

ENTRYPOINT [ "entrypoint.sh" ]

我的entrypoint.sh:

#!/bin/bash

service nginx start
service php7.1-fpm start

tail -F -n0 /etc/hosts

希望这可以为您提供帮助。