Dockerfile-错误:用于php无法启动服务php:OCI运行时创建失败:container_linux.go:348:启动容器进程导致“ exec

时间:2018-07-21 17:27:41

标签: php docker dockerfile

我是使用Docker的新手,我正在尝试创建一个本地开发环境来运行我的自定义php或laravel项目。

这是我的文件夹结构

root-dir
- src // this is where my php / laravel code lives
-- info.php // file having phpinfo(); just to ensure that everything has set properly
- docker // this is where all containers and config settings live
-- php etc..
- docker-compose.yml

这是我的docker / php / Dockerfile

FROM ubuntu:18.04

ENV TERM=linux

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y curl zip unzip --no-install-recommends apt-utils ca-certificates
RUN apt-get install -y --no-install-recommends php7.2-fpm \
                       php7.2-cli \
                       php7.2-mysql \
                       php7.2-xml \
                       php7.2-curl \
                       php7.2-bcmath \
                       php7.2-bz2 \
                       php7.2-curl \
                       php7.2-zip \
                       php7.2-gd \
                       php7.2-gettext \
                       php7.2-zip \
                       php7.2-soap \
                       php7.2-odbc \
                       php7.2-json \
                       php7.2-geoip \
                       php7.2-igbinary \
                       php7.2-imagick \
                       php7.2-mbstring \
                       php7.2-msgpack \
                       php7.2-ssh2 \
                       php7.2-memcached \
                       php7.2-xdebug \
                       php7.2-intl \
                       php7.2-opcache \
                       php7.2-readline

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* ~/.composer


COPY php.ini /etc/php/$PHPVER/cli/php.ini
COPY php.ini /etc/php/$PHPVER/fpm/php.ini
COPY 20-xdebug.ini /etc/php/$PHPVER/cli/conf.d/20-xdebug.ini
COPY 20-xdebug.ini /etc/php/$PHPVER/fpm/conf.d/20-xdebug.ini
COPY php-fpm-startup /usr/bin/php
CMD /usr/bin/php

EXPOSE 9000

ENTRYPOINT ["/usr/bin/php"]
CMD ["--version"]

运行docker-compose up -d时出现此错误

ERROR: for php  Cannot start service php: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/usr/bin/php\": permission denied": unknown

这是我的nginx / default.conf文件

server {

  listen 80 default_server;
  root /var/www/html;
  index index.html index.php;

  charset utf-8;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt { access_log off; log_not_found off; }

  access_log off;
  error_log /var/log/nginx/error.log error;

  sendfile off;

  client_max_body_size 100m;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
  }

  location ~ /\.ht {
    deny all;
  }
}

2 个答案:

答案 0 :(得分:0)

将用户添加到您的dockerfile中,它将为您执行php二进制文件,例如:

....
RUN ["chmod", "+x", "/usr/bin/php"]
RUN ["chmod", "+x", "-R", "/var/log"]
EXPOSE 9000
RUN useradd -ms /bin/bash admin
USER admin
ENTRYPOINT ["/usr/bin/php"]
CMD ["--version"]

答案 1 :(得分:0)

RE:聊天交流

不过,您担心容器为何停止运行。

如果您的命令完成执行,则容器将终止 如果您的命令失败并且tty死亡,则容器将终止。

换句话说,如果您的命令从不运行或无法运行并完成,例如您的示例

php -verson

是您尝试运行的代码 完成后,容器将终止 如果您没有抓住stdout,您将永远不会看到这个执行 容器将终止,好像什么也没发生。