首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Dockerfile - 错误:for php无法启动服务php:OCI运行时创建失败

Dockerfile - 错误:for php无法启动服务php:OCI运行时创建失败
EN

Stack Overflow用户
提问于 2018-09-03 00:27:20
回答 1查看 0关注 0票数 0

我是使用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-compose.yml文件

services:
    nginx:
        image: nginx:alpine
        container_name: webserver
        ports:
            - 8888:80
        volumes:
            - ./src:/var/www/html
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default 
        depends_on:
            - php
        networks:
            - appnet
    php:
        build:
            context: ./docker/php
            dockerfile: Dockerfile
        image: lykos/php:latest
        container_name: php
        depends_on:
            - mysql
        volumes:
            - ./src:/var/www/html
        networks:
            - appnet
    mysql:
        image: mysql:5.7
        container_name: mysql
        environment:
            MYSQL_ROOT_PASSWORD: secret
            MYSQL_DATABASE: homestead
            MYSQL_USER: homestead
            MYSQL_PASSWORD: secret
        volumes:
            - data:/var/lib/mysql
        networks:
            - appnet

networks:
    appnet:
        driver: bridge
volumes:
    data:
        driver: local

这是我的docker / php / Dockerfile

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y curl zip unzip --no-install-recommends apt-utils software-properties-common
RUN add-apt-repository -y ppa:ondrej/php

RUN apt-get update
RUN apt-get install -y php7.2-fpm php7.2-cli php7.2-mysql php7.2-xml php7.2-mcrypt  \
                       php7.2-bcmath php7.2-bz2 php7.2-curl 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

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN mkdir /run/php
RUN apt-get remove -y --purge software-properties-common

COPY config/php.ini /etc/php/7.2/cli/php.ini
COPY config/php.ini /etc/php/7.2/fpm/php.ini


EXPOSE 9000

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

一个。当我正在运行docker-compose up -d所有容器并尝试http:localhost:8888/info.php从URL 访问时,我找不到404。我运行了docker ps,唯一的活动容器是nginx和mysql容器,因此php容器没有运行。我改变了ENTRYPOINT ["php-fpm"],但是当我跑步时docker-compose build我得到了这个错误

ERROR: for php Cannot start service php: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"php-fpm\": executable file not found in $PATH": unknown

湾 在构建图像时我还有另一个问题,我明白了debconf: delaying package configuration, since apt-utils is not installed。正在运行的脚本不会停止,它会继续执行并构建容器。

在google上搜索之后我在我的脚本上放了apt-get install -y --no-install-recommended apt-utils(检查Dockerfile)但是这并没有解决问题。

任何想法如何解决这些问题?

编辑此外,我已经运行docker logs <nginx container id>并获取这些

172.28.0.1 - - [17/Jul/2018:19:57:06 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" "-"
172.28.0.1 - - [17/Jul/2018:19:57:12 +0000] "GET /info.php HTTP/1.1" 404 571 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" "-"
2018/07/17 19:57:12 [error] 9#9: *1 open() "/usr/share/nginx/html/info.php" failed (2: No such file or directory), client: 172.28.0.1, server: localhost, request: "GET /info.php HTTP/1.1", host: "localhost:8888"

这就是我跑步时得到的 docker logs <php container id>

PHP 7.1.19-1+ubuntu18.04.1+deb.sury.org+1 (fpm-fcgi) (built: Jul  9 2018 13:14:18)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.19-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

这是我的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;
  }
}
EN

回答 1

Stack Overflow用户

发布于 2018-09-03 09:46:30

第一个错误:debconf: delaying package configuration, since apt-utils is not installed不是错误。Apt通知你,它将在安装apt-utils后配置包。别担心。

第二个:ERROR: for php Cannot start service php: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"php-fpm\": executable file not found in $PATH": unknown我们应该解决。在ubuntu上确实没有php-fpm可执行文件。你应该设置你ENTRYPOINT/usr/sbin/php-fpm7.2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档