Docker和php "standard_init_linux.go:207:exec用户进程导致"exec格式错误"。入口点也无法读取可执行文件的参数



我有以下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

我设法通过在DockerfileENTRYPOINT中生成一个外壳来修复它:

CMD ["/bin/sh","-c","/usr/local/bin/entrypoint.sh", "php-fpm"]

我还在入口点脚本中修复了拼写错误:

#!/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"]

也不起作用。

您的entrypoint.sh中有错别字

#/bin/sh => #!/bin/sh

最好的方法是从exec格式切换到shell格式,以便启动入口点:

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

还要从中删除最后一个CMD,因为您可以看到ENTRYPOINT直接检索所需的参数。在您的情况下是传递要执行的命令,即php-fpm

正如您所看到的,正如@Ntwobike指出的那样修复拼写错误。

因此,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 php-fpm

并专注于解决其余 98 个问题(您有 99 个;))。

PS仍然 IDK 为什么会发生这种情况。

相关内容

  • 没有找到相关文章

最新更新