0

I am setting up a live and test environment for a website I am hosting. Currently, I am facing issues and I can't seem to figure out why it is happening. I am using a MySQL, Nginx and PHP-fpm container. I want both environments to have their own container group.

Container group A is the live environment and B will be referring to the test environment. Remember these references as they will be coming back in the code provided below.

I have changed the PHP-fpm and MySQL ports for group B so they don't interfere with group A. For MySQL this seems to work (until this point) but the PHP-fpm container doesn't seem to want to work.

The only time I had container group B functioning properly is when I changed my extra_hosts in my docker-compose for A but then A would stop working.

docker-compose.yml for A

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

docker-compose.yml for 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

Nginx 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

PHP-fpm Dockerfile (B)

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

Symfony.pool.conf (B) I changed the fpm listening port here

; A exposes :9001
listen = 0.0.0.0:9003

I am not getting any errors except 504 Gateway timeouts after a certain amount of time. I want to be able to run both environments on the same server but with separated containers as their services.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.