swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

docker以及docker-compose中再次启动失败 #693

Closed Aaron-QL closed 5 years ago

Aaron-QL commented 5 years ago

第一次docker-compose up正常启动,Ctrl+C停掉后再次启动,会报下面的错误,只有把runtime/swoft.pid文件删掉才能再次启动

Creating network "swoft_default" with the default driver
Creating swoft ... done
Attaching to swoft
swoft    | The HTTP server have been running!(PID: 1)

Dockerfile:

FROM php:7.2

ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# install PHP extensions

RUN apt-get update --fix-missing \
    && apt-get install -y --fix-missing \
      curl \
      vim \
      git \
      zip \
      wget \
      libz-dev \
      libssl-dev \
      libpcre3-dev \
      libnghttp2-dev \
    && apt-get clean \
    && apt-get autoremove \
    && docker-php-ext-install bcmath \
    && docker-php-ext-install sockets \
    && docker-php-ext-install pdo_mysql \
    && pecl install -o -f redis \
    && docker-php-ext-enable redis \
    && rm -rf /tmp/*

# Hiredis
RUN wget https://github.com/redis/hiredis/archive/v0.14.0.tar.gz -O hiredis.tar.gz \
    && mkdir -p hiredis \
    && tar -xf hiredis.tar.gz -C hiredis --strip-components=1 \
    && rm hiredis.tar.gz \
    && ( \
        cd hiredis \
        && make -j$(nproc) \
        && make install \
        && ldconfig \
    ) \
    && rm -r hiredis

# Swoole extension
RUN wget https://github.com/swoole/swoole-src/archive/v4.3.4.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
    cd swoole \
    && phpize \
    && ./configure --enable-async-redis --enable-mysqlnd --enable-openssl --enable-http2 \
    && make -j$(nproc) \
    && make install \
    ) \
    && rm -r swoole \
    && docker-php-ext-enable swoole

# Composer
#RUN curl -sS https://getcomposer.org/installer | php \
#    && mv composer.phar /usr/local/bin/composer \
#    && composer config -g repo.packagist composer https://packagist.phpcomposer.com \
#    && composer self-update --clean-backups

WORKDIR /var/www/html/swoft/

CMD ["php", "bin/swoft", "http:start"]

docker-compose.yml:

version: "3"
services:
  swoft:
    container_name: swoft
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "18306:18306"
    volumes:
      - /Users/qinlong/hbh/swoft:/var/www/html/swoft/:rw

    restart: unless-stopped
    networks:
      - default

networks:
  default:
Aaron-QL commented 5 years ago

之后尝试本地启动,报错:

(CONSOLE)ErrorException: Swoole\Process::kill(): swKill(1, 0) failed, Error: Operation not permitted[1]
At /Users/qinlong/hbh/swoft/vendor/swoft/server/src/Server.php line 764
Code Trace:
#0 [internal function]: Swoft\Error\DefaultErrorDispatcher->handleError(2, 'Swoole\\Process:...', '/Users/qinlong/...', 764, Array)
#1 /Users/qinlong/hbh/swoft/vendor/swoft/server/src/Server.php(764): Swoole\Process::kill(1, 0)
#2 /Users/qinlong/hbh/swoft/vendor/swoft/http-server/src/Command/HttpServerCommand.php(51): Swoft\Server\Server->isRunning()
#3 /Users/qinlong/hbh/swoft/vendor/swoft/stdlib/src/Helper/PhpHelper.php(51): Swoft\Http\Server\Command\HttpServerCommand->start()
#4 /Users/qinlong/hbh/swoft/vendor/swoft/console/src/ConsoleDispatcher.php(47): Swoft\Stdlib\Helper\PhpHelper::call(Array)
#5 /Users/qinlong/hbh/swoft/vendor/swoft/console/src/Application.php(200): Swoft\Console\ConsoleDispatcher->dispatch(Array)
#6 /Users/qinlong/hbh/swoft/vendor/swoft/console/src/Application.php(140): Swoft\Console\Application->doRun('http:start')
#7 /Users/qinlong/hbh/swoft/vendor/swoft/framework/src/Processor/ConsoleProcessor.php(43): Swoft\Console\Application->run()
#8 /Users/qinlong/hbh/swoft/vendor/swoft/framework/src/Processor/ApplicationProcessor.php(34): Swoft\Processor\ConsoleProcessor->handle()
#9 /Users/qinlong/hbh/swoft/vendor/swoft/framework/src/SwoftApplication.php(221): Swoft\Processor\ApplicationProcessor->handle()
#10 /Users/qinlong/hbh/swoft/bin/swoft(14): Swoft\SwoftApplication->run()
#11 {main}