Giter Site home page Giter Site logo

docker-lumen's Introduction

Docker + Lumen with Nginx, MySQL, and Memcached

image

Why?

Setting up an entire Lumen stack can be time consuming. This repo is a quick way to write apps in PHP using Lumen from an any Docker client. It uses docker-compose to setup the application services, databases, cache, etc...

Clone this repo

git clone https://github.com/saada/docker-lumen.git
cd docker-lumen

Create Lumen App

now, create the app in the images/php directory named app

docker run --rm -it -v $(pwd)/images/php:/app $(docker build -q .) composer create-project --prefer-dist laravel/lumen ./app

Configuration

There are two configurations using .env files. One .env file for docker-compose.yaml and another for the php application.

# copy both files and make changes to them if needed
cp .env.docker.example .env
cp .env.app.example images/php/app/.env

To change configuration values, look in the docker-compose.yml file and change the php container's environment variables. These directly correlate to the Lumen environment variables.

Docker Setup

Build & Run

docker-compose up --build -d

Navigate to http://localhost:80 and you should see something like this image

Success! You can now start developing your Lumen app on your host machine and you should see your changes on refresh! Classic PHP development cycle. A good place to start is images/php/app/routes/web.php.

Feel free to configure the default port 80 in docker-compose.yml to whatever you like.

Stop Everything

docker-compose down

Running Artisan commands

docker-compose exec php sh
# inside the container
cd ..
php artisan migrate
php artisan cache:clear

Contribute

Submit a Pull Request!

docker-lumen's People

Contributors

cybericecream avatar grumoll avatar isbkch avatar leckylao avatar mbbender avatar p3ll3 avatar saada avatar thor-x86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-lumen's Issues

Add xdebug

Hi, great project!

It would be nice to have xdebug working into the project, and maybe some instructions about mapping and configuration in vscode.

nginx.conf /var/www/html/public does not exist (on Mac)

First of all, you're doing great work. These linked containers helped me out a lot, because they allow me to work locally and (in the future) setup continuous integration. I noticed one issue, however.

Maybe it's me working on a Mac (although this should not be an issue when using Docker), but the folder /var/www/html/public in nginx.conf does not exist in container php. As a result, the browser returns 'File not found.' when I browse to localhost:80 (or 8080 in my case), since the nginx container tries to search for a file index.php in container php for a folder /var/www/html/public, which does not exist.

I tried several solutions, and this worked for me: /var/www/app/public does exist, so I recommend replacing 'html' by 'app'. Otherwise, changing lumen new app to lumen new html may be a solution, but I did not test that yet.

Invalid value in docker-compose.yml

Hi, my docker is saying:

The Compose file './docker-compose.yml' is invalid because:
php.environment.APP_DEBUG contains true, which is an invalid type, it should be a string, number, or a null

cheers!

alairock/lumen no longer exists

I am trying to start a project with this package, but the Create Lumen App step fails:

Unable to find image 'alairock/lumen:latest' locally
docker: Error response from daemon: pull access denied for alairock/lumen, repository does not exist or may require 'docker login'.
See 'docker run --help'.

I thing that the package alairock/lumen is no longer available

Class 'Memcached' not found

Hi, any artisan commands, i.e. php artisan make:migration create_users_table, produce the following:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Memcached' not found

performance

Did you encounter any performance issue?

I do a basic request and getting the response take 10 sec on average. I don't hit the database or so.

pls let me know, or how I can improve it,
Roy

Add https support

Hi,

It would be nice to have https support with e.g. letsencrypt.
But I'm not quite into the topic to do it all on my own.
I found a docker image that looks like it would be compatible with this one.
Can somebody have a look on it if this might work out:
https://hub.docker.com/r/linuxserver/letsencrypt/

Thanks

Permission denied on lumen.log writing

From a scratch success build run gets:

Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/lumen.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107 Stack trace: #0

And I run

docker-compose exec php ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.9 135220 18816 ? Ss 04:56 0:00 php-fpm: master process (/usr/local/etc/
www-data 5 0.0 0.6 135624 12552 ? S 04:56 0:00 php-fpm: pool www
www-data 6 0.0 0.6 135624 12552 ? S 04:56 0:00 php-fpm: pool www

So php is running ww-data

Then I run

docker-compose exec php ls -la /var/www/html/storage
total 0
drwxr-xr-x 1 1000 staff 102 Jun 22 04:36 .

So the folder is own by staff. Which caused the permission issue

My current solution is

  • Remove volume from docker-compose in php
  • at the end of php/Dockerfile adds
    COPY ./ /var/www/html
    RUN chown -R www-data:www-data /var/www/html

PDOException in Connector.php line 119: could not find driver

Hi,
I believe I have followed the Readme to the letter but am getting
in Connector.php line 119
at PDO->__construct('mysql:host=192.168.99.100;port=tcp://172.17.0.3:3306;dbname=lumen', 'lumen', 'secret', array('0', '2', '0', false, false)) in Connector.php line 119
at Connector->createPdoConnection('mysql:host=192.168.99.100;port=tcp://172.17.0.3:3306;dbname=lumen', 'lumen', 'secret', array('0', '2', '0', false, false)) in Connector.php line 56
at Connector->createConnection('mysql:host=192.168.99.100;port=tcp://172.17.0.3:3306;dbname=lumen', array('driver' => 'mysql', 'host' => '192.168.99.100', 'port' => 'tcp://172.17.0.3:3306', 'database' => 'lumen', 'username' => 'lumen', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'timezone' => '+00:00', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 24
at MySqlConnector->connect(array('driver' => 'mysql', 'host' => '192.168.99.100', 'port' => 'tcp://172.17.0.3:3306', 'database' => 'lumen', 'username' => 'lumen', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'timezone' => '+00:00', 'strict' => false, 'name' => 'mysql')) in ConnectionFactory.php line 100
at ConnectionFactory->Illuminate\Database\Connectors{closure}()
at call_user_func(object(Closure)) in Connection.php line 956
at Connection->getPdo() in Connection.php line 824
at Connection->reconnectIfMissingConnection() in Connection.php line 709
at Connection->run('select * from cars', array(), object(Closure)) in Connection.php line 351
at Connection->select('select * from cars', array(), true) in Builder.php line 1648
at Builder->runSelect() in Builder.php line 1634
at Builder->get(array('')) in Builder.php line 613
at Builder->getModels(array('
')) in Builder.php line 318
at Builder->get(array('*')) in Model.php line 632
at Model::all() in CarsController.php line 10
at CarsController->index()
at call_user_func_array(array(object(CarsController), 'index'), array()) in Container.php line 508
at Container->call(array(object(CarsController), 'index'), array()) in RoutesRequests.php line 610
at Application->callControllerCallable(array(object(CarsController), 'index'), array()) in RoutesRequests.php line 553
at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\CarsController@index'), array())) in RoutesRequests.php line 512
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\CarsController@index'), array())) in RoutesRequests.php line 497
at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\CarsController@index'), array())) in RoutesRequests.php line 394
at Application->Laravel\Lumen\Concerns{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing{closure}(object(Request)) in RequestLogMiddleware.php line 14
at RequestLogMiddleware->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in RoutesRequests.php line 647
at Application->sendThroughPipeline(array('App\Http\Middleware\RequestLogMiddleware'), object(Closure)) in RoutesRequests.php line 400
at Application->dispatch(null) in RoutesRequests.php line 341
at Application->run() in index.php line 28

exception when I try and connect and get anything from default database (as set up by the docker-compose command.

I have managed to get this working though by
docker exec -it dockerlumen_php_1 /bin/bash
php-fpm -m doesn't list pdo-mysql (only pdo-sqlite), so the quess is that the docker set up hasn't installed the correct module for mysql & pdo.
running
docker-php-ext-install pdo_mysql within the container gets the correct module installed (verified by php-fpm -m).
Keeping this setting saved though between restarts is the problem.
ctrl + p q to exit exec,
stop php docker container (not docker-compose), then restart it gets my lumen app to work (access the db), but doesn't handle restarts (of docker-compose).

Also, how does my database persist between restarts of docker compose??
Thanks

run php artisan migration

I'm trying to do migration using the following command:
$docker-compose exec <IMAGE_NAME> php artisan migrate
where <IMAGE_NAME> is php, but artisan is not found.

File not found

I am having problems with the error message "File not found". I have tried to change the path to: /var/www/html/app/public, /var/www/html/public, /var/www/html, but none of them works.

Getting Fatal Error

Hey, getting this error after running

docker-compose up --build -d

and browsing to http://localhost:80/

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /var/www/html/app/vendor/symfony/debug/Exception/FlattenException.php on line 41

Fatal error: Exception thrown without a stack frame in Unknown on line 0

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /var/www/html/app/vendor/symfony/debug/Exception/FlattenException.php on line 41

Fatal error: Exception thrown without a stack frame in Unknown on line 0

Also tried to change the port (80) but got the same error.

File not found

Hey,
I had a problem that browser was giving me text message like : File not found, so had to change paths to: /var/www/html/app/public. Do you want PR for that?

Just trying to run from scratch - error docker-php-ext-install instruction

I get the following error on docker-compose build. Will start investigating but wanted to post here incase this was familiar.

Step 3 : RUN docker-php-ext-install mcrypt mbstring tokenizer mysql
 ---> Running in 95be90350e29
error: /usr/src/php/ext/mysql does not exist

usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
   ie: /usr/local/bin/docker-php-ext-install gd mysqli
       /usr/local/bin/docker-php-ext-install pdo pdo_mysql
       /usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop

if custom ./configure arguments are necessary, see docker-php-ext-configure

Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mcrypt mbstring tokenizer mysql' returned a non-zero code: 1

Getting Error E: Unable to locate package php5-memcached

I get error below when I run docker-compose up --build -d

Thanks!

ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get install -y php5-memcached && docker-php-ext-install mcrypt mbstring tokenizer mysqli pdo_mysql && apt-get install -y libz-dev libmemcached-dev && pecl install memcached && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini' returned a non-zero code: 100

Docker new version

I just updated docker to the latests versions, and somehow it stopped working, I just can't access to it.

Can it be it is related to the Docker version?

Thanks

Permissions errors

In default install lumen app i have some permission errors when i am trying to save my view files

I fix this by this command:
chmod 777 -R /storage

But i have a new error, nginx/docker/lumen doesn't see my assets files (css/images/js) in public folder

P.S:: routing works perfectly

For example i have these:

/images/php/app/app/Http/routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app->get('/', function () use ($app) {
    return view('index');
});

$app->get('instruction', function () use ($app) {
    return view('instruction');
});

$app->get('cart/get', 'CartController@get');

$app->get('newsletter/subscribe', 'NewsletterController@subscribe');

/images/php/app/resources/views/instruction.blade.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet"
            href="instruction-assets/bootstrap.min.css">
    </head>
    <body>
        <div class="container-test">
            <div>
                <img src="img/products/bag.jpg">
            </div>
        </div>
    </body>
</html>

instruction-assets/bootstrap.min.css -> 404
img/products/bag.jpg -> 404

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.