【问题标题】:Docker doesn't run entrypoint scriptDocker 不运行入口点脚本
【发布时间】:2017-10-27 06:09:48
【问题描述】:

不明白为什么 Docker 忽略了我的 docker-endpoint.sh

Dockerfile

FROM php:7.1-apache

RUN a2enmod rewrite expires

RUN set -ex \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        libjpeg-dev \
        libpng-dev \
        libcurl4-openssl-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
    && docker-php-ext-install opcache gd pdo_mysql zip

WORKDIR /var/www/html

COPY config/php/php.ini /usr/local/etc/php/
COPY docker-entrypoint.sh /usr/local/bin/

RUN set -xe \
    chown -R www-data:www-data . \
    && chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["apache2-foreground"]

docker-entrypoint.sh

#!/bin/bash

set -e

echo "Hello"

exec "$@"

我希望看到“你好”。容器正常启动,没有错误,但是 Apache 不工作。安装了 Bash。我还尝试用 #!/bin/sh 替换 #!/bin/bash 甚至删除它 - 结果相同。

UPD。 php.ini

[PHP]

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 120

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 256M

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 10M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 10M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = Off

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=4000

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=2

; If enabled, a fast shutdown sequence is used for the accelerated code
opcache.fast_shutdown=1

【问题讨论】:

    标签: bash docker


    【解决方案1】:

    我使用了您的 Dockerfile 和端点,并在进行一次修改后运行了两个命令(注释掉 php.ini 副本)

    docker build . -t me/foo
    docker run me/foo
    

    镜像构建成功,容器启动成功,控制台显示Hello。我认为 ENTRYPOINT 不是问题。

    我会检查你的 php.ini 文件。

    如果您可以将其发布在您的原始问题中,并在添加时对我的答案添加评论,我将很高兴再次审核。

    【讨论】:

    • 你的操作系统是什么?我是win,会不会和编码、换行等有关?
    • 我添加了 php.ini
    • @ymakux 我在 MacOS 上,并再次检查了您的 php.ini。一切看起来都不错。是的,docker-entrypoint.sh 文件中的新行可能存在问题。请做测试,如果你跟进,我会删除我的答案(可能应该是评论,取决于你问谁)
    • 问题似乎是:“[I] 不明白为什么 Docker [is] 忽略了我的 docker-endpoint.sh”。如果答案是:“Docker 没有忽略您的 docker-endpoint.sh 脚本,这实际上是您的 php.ini 的问题”,那么这就是问题的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 2016-12-17
    相关资源
    最近更新 更多