phplaraveldockerdocker-composeswoole

Laravel Swoole Docker "There are no commands defined in the "swoole" namespace"


So, I want to configure the swoole laravel project. I run a Dockerfile and it successfully run. Then I want to run compose file this give me error

There are no commands defined in the "swoole" namespace.

This is my first experience with swoole. And I don't understand what is the problem.

How can solve this problem?

This is a Dockerfile

FROM php:8.1-fpm-alpine
# Install laravel requirement PHP package
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libzip-dev sqlite-dev \
            libpng-dev libxml2-dev oniguruma-dev libmcrypt-dev curl curl-dev libcurl postgresql-dev
RUN docker-php-ext-install -j$(nproc) gd bcmath zip pdo_mysql pdo_pgsql
RUN pecl install  xdebug swoole && docker-php-ext-enable  swoole
# Install composer
ENV COMPOSER_HOME /composer
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer

# Install PHP_CodeSniffer
WORKDIR /app
COPY ./ ./


USER root

RUN chown -R www-data /app/storage
RUN chmod -R ug+w /app/storage
RUN  chmod 777 -R /app/storage
RUN  chmod 777 -R /app/public



RUN composer install
RUN php artisan optimize

CMD php artisan swoole:http start
EXPOSE 1215

And this is a docker-compose.yaml file

version: "3.7"
services:
  app:
    build:
      args:
        user: www-data
        uid: 1000
      context: ./
      dockerfile: Dockerfile
    image: topspot-swoole-image
    container_name: topspot-swoole-container
    restart: unless-stopped
    working_dir: /var/www/
    volumes:
      - ./:/var/www
    networks:
      - topspot-network

  nginx:
    image: nginx:alpine
    container_name: topspot-nginx
    restart: unless-stopped
    ports:
      - 80:80
    volumes:
      - ./:/var/www
      - ./docker-compose/nginx:/etc/nginx/conf.d/
    networks:
      - topspot-network

networks:
  topspot-network:
    driver: bridge

Solution

  • Solved

    I solved it. Firstly install the swoole and publish to a local project. Then run the container and the composer saw the Swoole packages.