hyperf / watcher

[READ ONLY]
18 stars 11 forks source link

Hot Reload Not Working in Dockerized Hyperf Application Using hyperf/watcher #28

Closed azonedev closed 3 months ago

azonedev commented 3 months ago

I am using this base image : hyperf/hyperf:8.3-alpine-v3.19-swoole-slim

Docker compose setup :

hyperf-skeleton:
  container_name: hyperf
  image: hyperf/hyperf:8.3-alpine-v3.19-swoole-slim
  build:
    context: .
  volumes:
    - ./:/opt/www
  ports:
    - "9501:9501"
  working_dir: /opt/www
  command: [ "php", "bin/hyperf.php", "server:watch" ]
  environment:
    - APP_ENV=${APP_ENV}
    - SCAN_CACHEABLE=false

Container Error log :

hyperf             | [DEBUG] [command] Commands registered by Hyperf\Command\Listener\RegisterCommandListener
hyperf             | [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Command\Listener\RegisterCommandListener listener.
hyperf             | [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
hyperf             | [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Database\PgSQL\Listener\RegisterConnectionListener listener.
hyperf             | [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
hyperf             | [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
hyperf             |                                                          
hyperf             |   No arguments expected for "start" command, got "php".  
hyperf             |                                                          
hyperf exited with code 1
azonedev commented 3 months ago

The issue resolved with this Dockerfile and config

FROM hyperf/hyperf:8.3-alpine-v3.19-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
    APP_ENV=prod \
    SCAN_CACHEABLE=(true)

# update
RUN set -ex \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    #  ---------- some config ----------
    && cd /etc/php* \
    # - config PHP
    && { \
        echo "upload_max_filesize=128M"; \
        echo "post_max_size=128M"; \
        echo "memory_limit=1G"; \
        echo "date.timezone=${TIMEZONE}"; \
    } | tee conf.d/99_overrides.ini \
    # - config timezone
    && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    # ---------- clear works ----------
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

WORKDIR /opt/www

# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts

COPY . /opt/www
RUN composer install && php bin/hyperf.php

EXPOSE 9501

ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "server:watch"]