尝试在traefik代理后面为同一应用程序的不同环境运行多个php-fpm容器的问题

时间:2019-06-11 16:10:07

标签: docker nginx docker-compose traefik fpm

我正在为我托管的网站设置实时测试环境。目前,我正面临一些问题,而且似乎无法弄清为什么会这样。我正在使用MySQL,Nginx和PHP-fpm容器。我希望两种环境都具有自己的容器组。

容器组A是现场环境,而B组将指测试环境。请记住这些参考,因为它们将在下面提供的代码中返回。

我已经更改了B组的PHP-fpm和MySQL端口,因此它们不会干扰A组。对于MySQL来说,这似乎可行(到现在为止),但PHP-fpm容器似乎不想工作。

我唯一的容器组B正常运行是当我在docker-compose中将我的extra_hosts更改为A时,但是A会停止工作。

docker-compose.yml为A

wedges = []
for row in semicircle_specs:
    wedge = Wedge((row['x'], row['y']), RADIUS, row['angle'], row['angle'] + 180)
    wedges.append(wedge)

docker-compose.yml for B

Same as the file below but uses port 9000:9001 for PHP

Nginx Dockerfile(B)

version: '3.7'

networks:
  web:
    external: true
  internal:
    external: false

services:
  # MySQL container code sits here but I think there is nothing wrong 
    with that one

  php:
    build: ./.docker/php-fpm
    ports:
    - "9002:9003"
    volumes:
    - ./:/var/www/symfony:cached
    - ./logs/symfony:/var/www/symfony/var/log:cached
    links:
    - db
    restart: always
    extra_hosts:
    - "docker-host.localhost:127.0.0.1" # Changing this to test-docker-host.localhost:127.0.0.1 doesn't work either.
    networks:
    - internal
    labels:
    - traefik.enable=false

  nginx:
    build: ./.docker/nginx
    links:
    - php
    volumes:
    - ./:/var/www/symfony:cached
    - ./logs/nginx:/var/log/nginx:cached
    restart: always
    networks:
    - internal
    - web
    labels:
    - traefik.backend=Test-Website
    - traefik.frontend.rule=Host:test.website.com
    - traefik.frontend.redirect.regex=^https?://website.com/(.*)
    - traefik.frontend.redirect.replacement=https://test.website.com/$${1}
    - traefik.docker.network=web
    - traefik.port=80
    depends_on:
    - db

PHP-fpm Dockerfile(B)

FROM alpine:3.8

RUN apk add --update nginx
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*

ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
RUN rm -rf /etc/nginx/conf.d/default.conf

RUN echo "upstream php-upstream { server php:9003; }" > /etc/nginx/conf.d/upstream.conf # A uses php:9001

RUN adduser -D -g '' -G www-data www-data

RUN chown -R www-data.www-data /var/tmp/nginx

CMD ["nginx"]

EXPOSE 80
EXPOSE 443

Symfony.pool.conf(B)我在这里更改了fpm监听端口

FROM alpine:3.8

RUN apk add --update \
    php7-fpm \
    php7-apcu \
    php7-ctype \
    php7-curl \
    php7-dom \
    php7-gd \
    php7-iconv \
    php7-imagick \
    php7-json \
    php7-intl \
    php7-mcrypt \
    php7-fileinfo\
    php7-mbstring \
    php7-opcache \
    php7-openssl \
    php7-pdo \
    php7-pdo_mysql \
    php7-mysqli \
    php7-xml \
    php7-zlib \
    php7-phar \
    php7-tokenizer \
    php7-session \
    php7-simplexml \
    php7-xdebug \
    php7-zip \
    make \
    curl \
    nodejs \
    yarn \
    autoconf \
    libtool \
    automake \
    build-base \
    nasm \
    pkgconfig \
    zlib-dev \
    libpng-dev \
    g++

RUN rm -rf /var/cache/apk/* && rm -rf /tmp/* && \
    curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer

ADD symfony.ini /etc/php7/conf.d/
ADD symfony.ini /etc/php7/cli/conf.d/
ADD xdebug.ini  /etc/php7/conf.d/

ADD symfony.pool.conf /etc/php7/php-fpm.d/

CMD ["php-fpm7", "-F"]

WORKDIR /var/www/symfony
EXPOSE 9003 # A exposes 9001

除了经过一定时间后504网关超时外,我没有其他任何错误。我希望能够在同一台服务器上运行两个环境,但将容器作为服务使用单独的容器。

0 个答案:

没有答案