reactphp / reactphp

Event-driven, non-blocking I/O with PHP.

Home Page:https://reactphp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[RFC] Implement a docker repository on Docker hub

NigelGreenway opened this issue · comments

As Docker is picking up a big following and people are switching to containerisation I feel it would be worth getting an image on Docker Hub. As ReactPHP is a php process, I feel it would be beneficial to use the alpine images.

I feel it would be worth having the following:

  • Docs on what the image is doing
  • An example using the Docker image

Sounds interesting, knowing a bit about docker, what would be included in a ReactPHP container ?

a standard php7 container with libevent will do.

@baskan I was thinking something similar, but would you give an image for supported versions of PHP5-7 and then a version of each event lib, so:

php5.6 - libevent
php5.6 - libev
php5.6 - event
php7.1 - libevent
php7.1 - libev
php7.1 - event

I would then suggest to only create it from the php*-alpine images.

@baskan sure at the bare minimum, but what about extra extensions? For example react/filesystem can utilise ext-eio and I'm also working on pthreads support. Also I would highly appreciate the ability to add extra extensions packed with the OS and those from PECL. As each application is differently and uses different extensions.

@WyriHaximus yeah good point, we should create a .env with with all those settings and a Dockerfile checks those enviroment settings (a good example is here: https://github.com/laradock/laradock/blob/master/php-fpm/Dockerfile-71)

commented

Came across this issue trying to find if anyone tried to run reactphp in a container.
Currently I'm using this to run the server.

$ docker run -d -p 1337:1337 -v "$PWD":/react -w /react php:7-zts php server.php 1337

server.php

<?php
require 'vendor/autoload.php';

$i = 0;

$app = function ($request, $response) use (&$i) {
    $i++;

    $text = "This is request number $i.\n";
    $headers = array('Content-Type' => 'text/plain');

    $response->writeHead(200, $headers);
    $response->end($text);
};

$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);

$http->on('request', $app);

echo "Listening on $argv[1]";
$socket->listen($argv[1], '::');
$loop->run();

@diego-vieira is done it like so for the moment :

https://github.com/NigelGreenway/reactive-slim/blob/master/Dockerfile

But, this RFC would some that issue. Also, I've created a systemd service file to handle it which I can post tomorrow, here.

Check out this (script part) on how I use it.

This is the service config I am working on:

# /path/to/systemd/services/react-php.service
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades.  If you want to customize,
# the best way is to use the "systemctl edit" command.

[Unit]
Description=The ReactPHP Process Manager
After=network.target

[Service]
Type=simple
WorkingDirectory=/path/to/your/reactphp/app
PIDFile=/var/run/react-php.pid
ExecStart=/usr/bin/bash -lc 'php server.php'
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

If we get this into the docker container, it means we can use docker run systemctl react-php (stoprestart) then maybe have something watching for file changes and run restart automatically?

// @diego-vieira

I've been playing around with using an init system and alpine (as I'm using the official PHP Docker image) and it's turning out to be hard work (although I am still new to this Docker + Linux stuff).

What are peoples thoughts on something like this:

FROM php:7.0-alpine

COPY . /var/app
WORKDIR /var/app

RUN apk update
RUN apk add --update zlib-dev
RUN docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) iconv
RUN rm -rf /tmp/*

EXPOSE 1337

ENTRYPOINT php /src/server.php

I've been doing a bit of work on this and have hit a snag; when you have a composer container as well as you app container I am struggling to get them communicating in separate containers.

@NigelGreenway composed containers can communicate eachother with their container name assigned as a host.

assuming you are within container1:

ping container2

command will ping the "container2" named container. If you can push the repo somewhere I could take a look.

check PR #383

Thank you for filing this ticket and sparking the discussion!

I think Docker is really awesome for a large number of use cases and it makes perfect sense to build ReactPHP-based Docker images and share them on Docker Hub! :shipit: 🎉

However, given the fact that ReactPHP is set of independent components and not an application you can run, I don't really see how we could provide something even remotely similar to a "base image" here. There are a large number of applications that use ReactPHP and for some of them it appears reasonable to also provider Docker images. However, the way these images are composed depends entirely on the application at hand.

I hope this helps 👍

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍