# Mezzio with docker and nginx web server

**URL:** <https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933>\
**Category:** Mezzio\
**Tags:** mezzio-swoole\
**Created:** [June 23, 2022, 7:53pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933 "2022-06-23T19:53:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sirpyerre](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/sirpyerre/32/897_2.png) [@Sirpyerre](https://discourse.laminas.dev/u/Sirpyerre)\
**Post date:** [June 23, 2022, 7:53pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933/1 "2022-06-23T19:53:34Z")

</div>

Hi.  
Are there some Docker images to work with Nginx and mezzio? Or do I need to create from scratch?

Thank you.

---

<div class="post-metadata">

**Author:** ![ocramius](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ocramius/32/23_2.png) [@ocramius](https://discourse.laminas.dev/u/ocramius)\
**Post date:** [June 23, 2022, 8:32pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933/2 "2022-06-23T20:32:51Z")

</div>

Any php-fpm image should work fine.

Marco Pivetta

---

<div class="post-metadata">

**Author:** ![linuxdev](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/linuxdev/32/898_2.png) [@linuxdev](https://discourse.laminas.dev/u/linuxdev)\
**Post date:** [September 17, 2022, 3:43pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933/3 "2022-09-17T15:43:57Z")

</div>

@ [Sirpyerre](https://discourse.laminas.dev/u/Sirpyerre)  
Hi - I wrote a post on setting up dockerized mezzio with nginx (will working php-8.1 and nginx dockerfiles and docker-compose).  
^ This specific post is for mezzio/swoole variant specifically - bu I plan to follow up soon with php-fpm version as well soon.

[https://bytepursuits.com/mezzio-using-swoole-openswoole-with-nginx-reverse-proxy-with-docker-containers-and-docker-compose](https://bytepursuits.com/mezzio-using-swoole-openswoole-with-nginx-reverse-proxy-with-docker-containers-and-docker-compose)

---

<div class="post-metadata">

**Author:** ![linuxdev](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/linuxdev/32/898_2.png) [@linuxdev](https://discourse.laminas.dev/u/linuxdev)\
**Post date:** [September 18, 2022, 8:10pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933/4 "2022-09-18T20:10:24Z")

</div>

@ [Sirpyerre](https://discourse.laminas.dev/u/Sirpyerre) here’s the example of how to set up nginx with php-fpm mezzio container (using docker containers):

[https://bytepursuits.com/mezzio-using-phpfpm-with-nginx-reverse-proxy-with-docker-containers-and-docker-compose](https://bytepursuits.com/mezzio-using-phpfpm-with-nginx-reverse-proxy-with-docker-containers-and-docker-compose)

---

<div class="post-metadata">

**Author:** ![Leafar\_Avlis](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/leafar_avlis/32/598_2.png) [@Leafar\_Avlis](https://discourse.laminas.dev/u/Leafar_Avlis)\
**Post date:** [January 4, 2023, 6:59pm UTC](https://discourse.laminas.dev/t/mezzio-with-docker-and-nginx-web-server/2933/5 "2023-01-04T18:59:50Z")

</div>

I use this config to run mezzio/swoole as a microservice

add swoole with composer

```auto
composer require mezzio/mezzio-swoole

```

file config/autoload/swoole.global.php

```auto
<?php

use Mezzio\Swoole\Event\TaskEvent;
use Mezzio\Swoole\Task\DeferredServiceListenerDelegator;
use Mezzio\Swoole\Task\TaskInvokerListener;
use Psr\EventDispatcher\EventDispatcherInterface;
use SwooleTasks\ServicesTasks\Factory\RunServiceTaskFactory;
use SwooleTasks\ServicesTasks\Factory\ServicesTasksEventListenerFactory;
use SwooleTasks\ServicesTasks\RunServiceTask;
use SwooleTasks\ServicesTasks\ServicesTaskPayloadEvent;
use SwooleTasks\ServicesTasks\ServicesTasksEventListener;

return [

    'dependencies' => [
        'invokables' => [
            EventDispatcherInterface::class => EventDispatcherInterface::class,
        ],
        'factories' => [
            //ServicesTasksEventListener::class => ServicesTasksEventListenerFactory::class,
            //RunServiceTask::class => RunServiceTaskFactory::class
        ],
        'delegators' => [
            //ServicesTasksEventListener::class => [
            // DeferredServiceListenerDelegator::class,
            //]
        ],
    ],

    'mezzio-swoole' => [

        //'enable_coroutine' => true , //optional to enable coroutines and useful for tasks coroutines
        'swoole-http-server' => [

            'host' => 'localhost',
            'port' => 9501,
            //'mode' => SWOOLE_PROCESS,
            'mode' => SWOOLE_BASE,
            'protocol' => SWOOLE_SOCK_TCP,
            //'protocol' => SWOOLE_SOCK_TCP|SWOOLE_SSL,
            'options' => [
                'enable_coroutine' => false,
                'max_coroutine' => 3000,

                'worker_num' => 10, // The number of HTTP Server Workers
                'task_worker_num' => 0, // The number of Task Workers
                'task_enable_coroutine' => false, // optional to turn on task coroutine support
                'task_use_object' => true, // allow json object as string

                'max_request' => 0,
                'max_request_grace' => 0 / 2,

                'open_tcp_keepalive' => false, // Enable TCP Keep-Alive check
                'tcp_keepidle' => 1, // Check if there is no data for 4s.
                'tcp_keepinterval' => 0.5, // Check if there is data every 1s
                'tcp_keepcount' => 1, // Close the connection if there is no data for 5 cycles.

                'heartbeat_check_interval' => 5,
                'heartbeat_idle_time' => 5,

                'max_conn' => 100_000,
                //'pipe_buffer_size' => 32 * 1024*1024,
                //'socket_buffer_size' => 128 * 1024*1024,

                'ssl_cert_file' => __DIR__. '/../../data/ssl/certificate.pem',
                'ssl_key_file' => __DIR__. '/../../data/ssl/certificate.key',

                /**
                 * ozzpy
                 * this do not work, because chrome(extension) detect man in the middle
                 * wireshark logs confirm it, and wrong hello response
                'ssl_cert_file' => __DIR__.'/config/ssl.crt',
                'ssl_key_file' => __DIR__.'/config/ssl.key',
                'ssl_verify_peer' => true,
                'ssl_allow_self_signed' => true,
                'ssl_client_cert_file' => __DIR__. '/config/client.crt',
                 */

            ],

            'listeners' => [
                /*
                ServicesTaskPayloadEvent::class => [
                    ServicesTasksEventListener::class
                ],
                TaskEvent::class => [
                    TaskInvokerListener::class,
                    #TaskEventDispatchListener::class,
                ],
                */
            ],
        ]
    ],

];

```

Dockerfile

```auto
FROM php:8.0-cli

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

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions swoole-4.8.2 uuid mcrypt intl mysqli pdo_mysql pcntl posix
RUN install-php-extensions @composer
RUN mkdir -p /var/www/app/

COPY ./php.ini "$PHP_INI_DIR/php.ini"
COPY . /var/www/app/
WORKDIR /var/www/app/

EXPOSE 9501
CMD ["php", "./public/index.php"]

```

Build image

```auto
docker build -t username/categories-micro .
docker push username/categories-micro

```

Run service on server or localhost

```auto
docker swarm init
docker network create -d overlay backend

docker login -u username -p [password]

docker pull username/categories-micro
docker service create --name categories-api-srv -p 9501:9501 --network backend --replicas 4 username/categories-micro

# running other microservice
docker service create --name sections-api-srv -p 9502:9501 --network backend --replicas 4 username/sections-micro

```

This code and image also works with kubernetes
