gpt4 book ai didi

php - Docker和php “standard_init_linux.go:207: exec user process caused ” exec格式错误”。入口点也无法读取exec的参数

转载 作者:行者123 更新时间:2023-12-02 18:28:01 30 4
gpt4 key购买 nike

我有以下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版本是:
$ 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

    我设法通过将 shell 生成到 ENTRYPOINTDockerfile中来修复它:
    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"]

    也不起作用。

    最佳答案

    您的entrypoint.sh中有一个错字

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

    关于php - Docker和php “standard_init_linux.go:207: exec user process caused ” exec格式错误”。入口点也无法读取exec的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56598381/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com