0

I have the following dockerfiles:

  • Dockerfile_develop_1:
#For Stackoverflow error reproduction
FROM php:7.2-fpm-alpine

ARG USERID=1000
ARG GROUPID=1000

ENV DOCKER_UID=${USERID} \
    DOCKER_GID=${GROUPID} \
    FPM_CONF_DIR="/usr/local/etc/php-fpm.d"

RUN echo "Installing Development Dpendencies \n" &&\
    echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories &&\
    apk add --update bash shadow git bash-completion bash-doc &&\
    addgroup -g ${DOCKER_GID} developer &&\
    mkdir -p /home/developer/code &&\
    adduser -D -u ${DOCKER_UID} -G developer -h /home/developer -s /bin/bash developer &&\
    chown developer:developer -R /home/developer/code &&\
    chmod 775 /home/developer/code &&\
    chown -R developer /home/developer &&\
    sed -i 's/www-data/developer/gi' ${FPM_CONF_DIR}/www.conf &&\
    rm -rf /var/cache/apk/*

COPY ./entrypoint/develop_entrypoint.sh /usr/local/bin/entrypoint.sh

# I make seperate layer because Entrypoint is most likely to change
RUN echo "Fixing Permissions on Entrypoint Script \n" &&\
    chown root:root /usr/local/bin/entrypoint.sh &&\
    chmod +x /usr/local/bin/entrypoint.sh

VOLUME /home/developer/code
WORKDIR /home/developer/code

ENTRYPOINT /usr/local/bin/entrypoint.sh php-fpm
  • Dockerfile_develop_2
#For Stackoverflow error reproduction
FROM php:7.2-fpm-alpine

ARG USERID=1000
ARG GROUPID=1000

ENV DOCKER_UID=${USERID} \
    DOCKER_GID=${GROUPID} \
    FPM_CONF_DIR="/usr/local/etc/php-fpm.d"

RUN echo "Installing Development Dpendencies \n" &&\
    echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories &&\
    apk add --update bash shadow git bash-completion bash-doc &&\
    addgroup -g ${DOCKER_GID} developer &&\
    mkdir -p /home/developer/code &&\
    adduser -D -u ${DOCKER_UID} -G developer -h /home/developer -s /bin/bash developer &&\
    chown developer:developer -R /home/developer/code &&\
    chmod 775 /home/developer/code &&\
    chown -R developer /home/developer &&\
    sed -i 's/www-data/developer/gi' ${FPM_CONF_DIR}/www.conf &&\
    rm -rf /var/cache/apk/*

COPY ./entrypoint/develop_entrypoint.sh /usr/local/bin/entrypoint.sh

# I make seperate layer because Entrypoint is most likely to change
RUN echo "Fixing Permissions on Entrypoint Script \n" &&\
    chown root:root /usr/local/bin/entrypoint.sh &&\
    chmod +x /usr/local/bin/entrypoint.sh

VOLUME /home/developer/code
WORKDIR /home/developer/code

ENTRYPOINT /usr/local/bin/entrypoint.sh php-fpm

With them I try to make php images for development purpoces that will map the user developer into my system's user without having the images messing up with user_id of my files. Therefore I try to configure the pool as a different user and then I map the user id and the group if of local user into the developer one used inside the docker container instance.

For building and launching them I use the following docker-compose.yml file:

version: '3.7'

services: 
  develop_1:
    build:
      context: .
      dockerfile: ./dockerfiles/Dockerfile_develop_1
    image: pcmagas/php:dev_1
    volumes:
      - "nginx-php:/home/developer/code"

  develop_2:
    build:
      context: .
      dockerfile: ./dockerfiles/Dockerfile_develop_2
    image: pcmagas/php:dev_2
    volumes:
      - "nginx-php:/home/developer/code"

  nginx:
    image: nginx:alpine
    ports:
      - 7880:7880
    links:
      - "develop_1:develop_1"
      - "develop_2:develop_2"
    volumes:
      - "nginx-php:/var/www/html"
      - "./conf/nginx.conf:/etc/nginx/nginx.conf:ro"

volumes:
  nginx-php: 
     driver: local
     driver_opts:
      o: bind
      type: none
      device: /home/pcmagas/code/docker_php_dev_stackoverflow/www

And I use the following entrypoint.sh script for both image's entrypoint:

 #!/bin/sh

USER_ID=$(id -u developer)
GROUP_ID=$(id -g developer)

echo "Setting the correct user and group id for shell use"
if [ ${DOCKER_UID} != ${USER_ID} ]; then
  usermod -u ${DOCKER_UID} developer
fi

if [ ${DOCKER_GID} != ${GROUP_ID} ]; then
  groupmod -g ${DOCKER_GID} developer
fi

echo "Fixing execution permissions"
find /home/developer/code -iname "*.php" | xargs chmod 777

echo "Launch application"
exec "$@"

But for some reason I get the following error:

nginx_1      | 2019/06/18 09:30:24 [error] 6#6: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.30.0.1, server: dev2.localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://172.30.0.3:9000", host: "dev2.localhost:7880", referrer: "http://dev2.localhost:7880/"

Also for the dev1.localhost:

nginx_1      | 2019/06/18 09:30:39 [error] 6#6: *6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.30.0.1, server: dev1.localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://172.30.0.2:9092", host: "dev1.localhost:7880", referrer: "http://dev1.localhost:7880/"

For url mapping I use this hosts file entry:

127.0.0.1 dev1.localhost dev2.localhost

Do you know how I can fix that? For a bummy php code I use the following:

<?php phpinfo(); ?>

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.