6

dockerを使用して動作するlaravel環境があります。私のプロジェクトには、redis、mongodb、mysqldb、nodejs などの異なるコンテナーに複数のサービスがあります。プロジェクトでスーパーバイザーを使用して、ジョブを実行するためにキューと php の redis とやり取りしたいと考えています。いくつかのテストと調査を行いましたが、実際には機能しません。

ここに私のDockerFileがあります:

FROM php:7.3-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    mariadb-client \
    libpng-dev \
    libzip-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    cron \
    supervisor

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-configure bcmath --enable-bcmath
RUN docker-php-ext-install bcmath

# install mongodb ext
RUN pecl install mongodb \
    && docker-php-ext-enable mongodb

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy supervisor configs
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Copy existing application directory contents
COPY . /var/www

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["/usr/bin/supervisord"]

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

そして私の docker-compose.yml ファイル

version: '3'
services:

  #PHP Service
  php:
    build:
      context: .
      dockerfile: Dockerfile
    image: digitalocean.com/php
    container_name: php
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: php
      SERVICE_TAGS: dev
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
      - ./supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
    networks:
      - app-network

  #NODEJS Service
  nodejs: 
    image: node:10
    container_name: nodejs
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
    tty: true
    networks:
      - app-network

  #Nginx Service
  nginx:
    image: nginx:alpine
    container_name: nginx
    restart: unless-stopped
    tty: true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/var/www
      - ./nginx/conf.d/:/etc/nginx/conf.d/
    networks:
      - app-network

  #MySQL Service
  mysqldb:
    image: mysql:5.7.22
    container_name: mysqldb
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - dbdata:/var/lib/mysql
      - ./mysql/my.cnf:/etc/mysql/my.cnf
    networks:
      - app-network

  #MongoDB Service
  mongodb:
    image: mongo:3
    container_name: mongodb
    restart: unless-stopped
    tty: true
    ports: 
      - "27017:27017"
    networks: 
      - app-network

  #Redis Service
  redis:
    image: redis
    container_name: redis
    restart: unless-stopped
    tty: true
    ports: 
      - "${REDIS_PORT}:6379"
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge

#Volumes
volumes:
  dbdata: 
    driver: local

また、私の Supervisord.conf を見たいと思うかもしれません

[supervisord]
user=www
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/var/run/supervisord.pid
loglevel = INFO

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
username=www
password=www

[supervisorctl]
serverurl=unix:///var/run/supervisord.sock
username=www
password=www

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

[program:php-fpm]
command = /usr/local/sbin/php-fpm
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:ohwo-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan horizon
autostart=false
autorestart=true
user=www
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/laravel-worker.log

その設定から。php artisan horizonコンテナが稼働しているとき、phpコンテナで手動で実行するとキューイングが完全に機能するため、supervisordが機能していないようです。ところで、horizo​​n はキューイングに使用するツールです。

そしてsupervisorctl、phpコンテナでも実行しようとすると、このエラーが発生しましたunix:///var/run/supervisord.sock no such file

だから私は数ヶ月前に始めたばかりのdockerにかなり慣れていません。Linux で Supervisord を設定する方法は知っていますが、docker では動作しません。

だから私の愚かさを許してください:)

4

2 に答える 2