У меня есть следующее Dockerfile
:
FROM php:7.2-fpm-alpine
ARG USERID=1000
ARG GROUPID=1000
ENV DOCKER_UID=${USERID} \
DOCKER_GID=${GROUPID} \
PHP_CONF_DIR="/usr/local/etc/php/conf.d" \
XDEBUG_CONF_FILE=${PHP_CONF_DIR}/docker-php-ext-xdebug.ini \
XDEBUG_HOST="" \
XDEBUG_IDE_KEY="" \
XDEBUG_PORT=9000 \
XDEBUG_DBGP=FALSE
RUN echo "Installing Development Dpendencies \n" &&\
echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories &&\
apk add --update --virtual build-dependencies build-base gcc wget autoconf &&\
apk add --update bash shadow git bash-completion bash-doc &&\
echo "Installing composer \n" &&\
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" &&\
php -r "if (hash_file('sha384', '/tmp/composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" &&\
php /tmp/composer-setup.php --install-dir=/bin --filename=composer &&\
rm -rf /tmp/cpmposer-setup.php &&\
chmod +x /bin/composer &&\
echo "Installing xdebug" &&\
pecl install xdebug &&\
docker-php-ext-enable xdebug &&\
echo "Configuring Xdebug \n" &&\
echo "xdebug.remote_enable=1" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.max_nesting_level = 1000" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.remote_mode=req" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.remote_log=xdebug.log" >> ${XDEBUG_CONF_FILE} &&\
cp ${XDEBUG_CONF_FILE} ${XDEBUG_CONF_FILE}.orig &&\
echo "Making a Development User \n" &&\
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 &&\
apk del build-dependencies &&\
rm -rf /var/cache/apk/*
# I make seperate layer because Entrypoint is most likely to change
COPY ./entrypoint/develop_entrypoint.sh /usr/local/bin/entrypoint.sh
RUN echo "Fixing Permissions on Entrypoint Script \n" &&\
chown root:root /usr/local/bin/entrypoint.sh &&\
chmod +x /usr/local/bin/entrypoint.sh &&\
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"]
CMD ["php-fpm"]
И я использую следующее docker-compose.yml
, чтобы запустить его:
version: '3'
services:
develop:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile_base
image: myapp/php:dev-n-build
volumes:
- ${CODE_BASE_PATH}:/home/developer/code
nginx:
image: nginx:alpine
ports:
- 7080:7080
links:
- develop
volumes:
- ${CODE_BASE_PATH}:/home/developer/code
Но по какой-то причине я получаю следующую ошибку:
Creating network "dist_default" with the default driver
Creating dist_develop_1 ... done
Creating dist_nginx_1 ... done
Attaching to dist_develop_1, dist_nginx_1
develop_1 | standard_init_linux.go:207: exec user process caused "exec format error"
dist_develop_1 exited with code 1
Моя версия докера:
$ docker -v
Docker version 18.09.6, build 481bc77
И версия docker-compose
:
docker-compose version 1.24.0, build 0aa5906
Также мои entrypoint.sh
нам следующие:
#/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 "Setup xdebug"
cp ${XDEBUG_CONF_FILE}.orig ${XDEBUG_CONF_FILE}
if [ -z ${XDEBUG_HOST} ]; then
ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
XDEBUG_HOST=${ip}
fi
echo "xdebug.remote_host=${XDEBUG_HOST}" >> ${XDEBUG_CONF_FILE}
echo "xdebug.repomote_port=${XDEBUG_PORT}" >> ${XDEBUG_CONF_FILE}
if [ XDEBUG_DBGP = TRUE ]; then
echo "xdebug.remote.handler=dbgp" >> ${XDEBUG_CONF_FILE}
fi
if [ ! -z "${XDEBUG_IDE_KEY}" ]; then
echo "xdebug.idekey=\"${XDEBUG_IDE_KEY}\"" >> ${XDEBUG_CONF_FILE}
fi
echo "Launch application"
exec "$@"
Вот мне и интересно:
- Что означает
standard_init_linux.go:207: exec user process caused "exec format error"
.
- Как я могу решить эту проблему.
Редактировать 1
Мне удалось это исправить, породив оболочку в ENTRYPOINT
моего Dockerfile
:
CMD ["/bin/sh","-c","/usr/local/bin/entrypoint.sh", "php-fpm"]
Я также исправил опечатку в скрипте 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 "Setup xdebug"
cp ${XDEBUG_CONF_FILE}.orig ${XDEBUG_CONF_FILE}
if [ -z ${XDEBUG_HOST} ]; then
ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
XDEBUG_HOST=${ip}
fi
echo "xdebug.remote_host=${XDEBUG_HOST}" >> ${XDEBUG_CONF_FILE}
echo "xdebug.repomote_port=${XDEBUG_PORT}" >> ${XDEBUG_CONF_FILE}
if [ XDEBUG_DBGP = TRUE ]; then
echo "xdebug.remote.handler=dbgp" >> ${XDEBUG_CONF_FILE}
fi
if [ ! -z "${XDEBUG_IDE_KEY}" ]; then
echo "xdebug.idekey=\"${XDEBUG_IDE_KEY}\"" >> ${XDEBUG_CONF_FILE}
fi
echo "Launch application"
exec "$@"
Но по какой-то неловкой причине php-fpm
не запускается. У вас есть идеи, почему?
Если я изменю последнюю строку ом entrypoint.sh
с:
exec "$@"
В
echo "Params $@"
exec "$@"
Я получаю следующий вывод:
develop_1 | Setting the correct user and group id for shell use
develop_1 | Setup xdebug
develop_1 | Launch application
develop_1 | Params
nginx_1 | 2019/06/14 14:00:04 [emerg] 1#1: host not found in upstream "develop" in /etc/nginx/nginx.conf:32
nginx_1 | nginx: [emerg] host not found in upstream "develop" in /etc/nginx/nginx.conf:32
php-docker_base_1 exited with code 0
php-docker_develop_1 exited with code 0
php-docker_nginx_1 exited with code 1
Более старые попытки, такие как эта: https://github.com/ellakcy/docker-moodle/blob/master/dockerfiles/fpm_alpine/Dockerfile_mysql работали с точкой входа, которая: https://github.com/ellakcy/docker-moodle/blob/master/scripts/entrypoint.sh
Что-то изменилось в Docker и способе обработки точек входа?
Также, выполнив:
CMD ["/bin/sh","-c","/usr/local/bin/entrypoint.sh", "php-fpm"]
Также не работает.