#TIL : Run built-in server via Docker


04 Dec 2015 / by KhanhIceTea

Docker is the fast and clean way to run Linux programs.

We can run a PHP project via PHP built-in server and Docker.

docker run -it -p 8080:8080 -v `pwd`:/code php:7 php -S 0.0.0.0:8080 -t /code/web /code/web/server.php

With server.php content is

<?php

$filename = __DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
    return false;

}

// Run application below
$app = new Application();
$app->run();

Sound good ?