From 9c7054abe253386ca6aee81ed0a823f0a3045139 Mon Sep 17 00:00:00 2001 From: Amin Mkh Date: Sun, 29 May 2016 14:19:43 +0300 Subject: [PATCH 1/7] added mongodb image + PHP7 driver --- docker-compose.yml | 7 +++++++ mongo/Dockerfile | 12 ++++++++++++ php-fpm/Dockerfile-70 | 4 ++++ 3 files changed, 23 insertions(+) create mode 100644 mongo/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index dd3ad77d..5557da05 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -139,6 +139,13 @@ services: - "2080:2080" links: - beanstalkd + +### Mongo Container ############################ + + mongo: + build: ./mongo + ports: + - "27017:27017" ### Workspace Utilities Container ########################### diff --git a/mongo/Dockerfile b/mongo/Dockerfile new file mode 100644 index 00000000..9662d6fc --- /dev/null +++ b/mongo/Dockerfile @@ -0,0 +1,12 @@ +FROM mongo:latest + +MAINTAINER Mahmoud Zalt + +#COPY mongo.conf /usr/local/etc/mongo/mongo.conf + +VOLUME /var/lib/mongo + +CMD [ "mongod" ] + +EXPOSE 27017 + diff --git a/php-fpm/Dockerfile-70 b/php-fpm/Dockerfile-70 index 61f21d07..00235d77 100644 --- a/php-fpm/Dockerfile-70 +++ b/php-fpm/Dockerfile-70 @@ -23,6 +23,10 @@ RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-m && docker-php-ext-install memcached \ && rm /tmp/memcached.tar.gz +# Install mongodb driver +RUN pecl install mongodb +RUN echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/mongo.ini + RUN usermod -u 1000 www-data WORKDIR /var/www/laravel From 1090bb4db66303f9729c262edb290825b8220397 Mon Sep 17 00:00:00 2001 From: Amin Mkh Date: Mon, 30 May 2016 23:26:40 +0300 Subject: [PATCH 2/7] added mongodb driver for php5.5 5.6 --- php-fpm/Dockerfile-55 | 3 +++ php-fpm/Dockerfile-56 | 3 +++ php-fpm/Dockerfile-70 | 1 - php-fpm/laravel.ini | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/php-fpm/Dockerfile-55 b/php-fpm/Dockerfile-55 index 93d82c52..c71e2f84 100644 --- a/php-fpm/Dockerfile-55 +++ b/php-fpm/Dockerfile-55 @@ -19,6 +19,9 @@ RUN docker-php-ext-install \ RUN pecl install memcached \ && docker-php-ext-enable memcached +# Install mongodb driver +RUN pecl install mongodb + RUN usermod -u 1000 www-data WORKDIR /var/www/laravel diff --git a/php-fpm/Dockerfile-56 b/php-fpm/Dockerfile-56 index 5da34488..eb99c209 100644 --- a/php-fpm/Dockerfile-56 +++ b/php-fpm/Dockerfile-56 @@ -19,6 +19,9 @@ RUN docker-php-ext-install \ RUN pecl install memcached \ && docker-php-ext-enable memcached +# Install mongodb driver +RUN pecl install mongodb + RUN usermod -u 1000 www-data WORKDIR /var/www/laravel diff --git a/php-fpm/Dockerfile-70 b/php-fpm/Dockerfile-70 index 00235d77..c4920fa3 100644 --- a/php-fpm/Dockerfile-70 +++ b/php-fpm/Dockerfile-70 @@ -25,7 +25,6 @@ RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-m # Install mongodb driver RUN pecl install mongodb -RUN echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/mongo.ini RUN usermod -u 1000 www-data diff --git a/php-fpm/laravel.ini b/php-fpm/laravel.ini index 3580140c..b09f4664 100644 --- a/php-fpm/laravel.ini +++ b/php-fpm/laravel.ini @@ -1,3 +1,4 @@ date.timezone = UTC display_errors = Off -log_errors = On \ No newline at end of file +log_errors = On +extension=mongodb.so \ No newline at end of file From 4c06a03ead4db4e7fc1806fd0851ac812bed0b0d Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Wed, 1 Jun 2016 14:44:10 +0300 Subject: [PATCH 3/7] get mongo volum from the data container --- docker-compose.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5557da05..16ec1116 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,6 +33,7 @@ services: - /var/lib/redis - /var/lib/memcached - /var/lib/neo4j/data + - /var/lib/mongo:/data/db ### Nginx Server Container ################################## @@ -101,6 +102,15 @@ services: volumes_from: - data +### MongoDB Container ####################################### + + mongo: + build: ./mongo + ports: + - "27017:27017" + volumes_from: + - data + ### Redis Container ######################################### redis: @@ -139,13 +149,6 @@ services: - "2080:2080" links: - beanstalkd - -### Mongo Container ############################ - - mongo: - build: ./mongo - ports: - - "27017:27017" ### Workspace Utilities Container ########################### From 3ff4aaca79b485369995c11c96d409e5020b5712 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Wed, 1 Jun 2016 14:44:40 +0300 Subject: [PATCH 4/7] set the original volume path --- mongo/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongo/Dockerfile b/mongo/Dockerfile index 9662d6fc..897e6f06 100644 --- a/mongo/Dockerfile +++ b/mongo/Dockerfile @@ -4,9 +4,9 @@ MAINTAINER Mahmoud Zalt #COPY mongo.conf /usr/local/etc/mongo/mongo.conf -VOLUME /var/lib/mongo +VOLUME /data/db /data/configdb -CMD [ "mongod" ] +CMD ["mongod"] EXPOSE 27017 From 124a3553e6c0e12c2e69fb11a2596c1afb5ce538 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Wed, 1 Jun 2016 14:45:27 +0300 Subject: [PATCH 5/7] simple reformatting --- php-fpm/laravel.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php-fpm/laravel.ini b/php-fpm/laravel.ini index b09f4664..bc0f61dd 100644 --- a/php-fpm/laravel.ini +++ b/php-fpm/laravel.ini @@ -1,4 +1,4 @@ date.timezone = UTC display_errors = Off log_errors = On -extension=mongodb.so \ No newline at end of file +extension = mongodb.so From c4100b5052995c6f045ad590ccbf1038ac86d465 Mon Sep 17 00:00:00 2001 From: Amin Mkh Date: Sat, 11 Jun 2016 14:38:26 +0300 Subject: [PATCH 6/7] added php-mongodb extension --- workspace/Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/workspace/Dockerfile b/workspace/Dockerfile index 65534aba..6fef4a30 100644 --- a/workspace/Dockerfile +++ b/workspace/Dockerfile @@ -34,6 +34,12 @@ RUN apt-get update && apt-get install -y --force-yes \ php7.0-sqlite3 \ php7.0-zip \ php7.0-memcached \ + php-dev \ + libcurl4-openssl-dev \ + libedit-dev \ + libssl-dev \ + libxml2-dev \ + xz-utils \ sqlite3 \ libsqlite3-dev \ git \ @@ -63,6 +69,10 @@ RUN curl -s http://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/ \ && echo "alias composer='/usr/local/bin/composer.phar'" >> ~/.bashrc +# Install mongodb extension +RUN pecl install mongodb +RUN echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini + # Source the bash RUN . ~/.bashrc From 685c34d12d995a01e966784da41478987eb60979 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Sat, 11 Jun 2016 17:10:18 +0300 Subject: [PATCH 7/7] add Mongo Support to the Readme --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 958b6851..4b0c05c7 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ It's like Laravel Homestead but for Docker instead of Vagrant. - [Install Laravel from a Docker Container](#Install-Laravel) - [Run Artisan Commands](#Run-Artisan-Commands) - [Use Redis](#Use-Redis) + - [Use Mongo](#Use-Mongo) - [PHP](#PHP) - [Install PHP Extensions](#Install-PHP-Extensions) - [Change the PHP-FPM Version](#Change-the-PHP-FPM-Version) @@ -92,6 +93,7 @@ docker-compose up nginx mysql redis - PostgreSQL - MariaDB - Neo4j +- MongoDB - Redis - Memcached - Beanstalkd @@ -208,7 +210,7 @@ docker-compose up -d nginx mysql *Note: the PHP-FPM, Workspace, Application and Data Containers will automatically run.* -Supported Containers: `nginx`, `mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `memcached`, `beanstalkd`, `beanstalkd-console`, `workspace`, `data`, `php-fpm`, `application`. +Supported Containers: `nginx`, `mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `mongo`, `memcached`, `beanstalkd`, `beanstalkd-console`, `workspace`, `data`, `php-fpm`, `application`. @@ -512,9 +514,6 @@ Composer update ```bash phpunit ``` -```bash -laravel new blog -``` @@ -527,7 +526,11 @@ laravel new blog ### Use Redis -1 - First make sure you run the Redis Container with the `docker-compose` command. +1 - First make sure you run the Redis Container (`redis`) with the `docker-compose up` command. + +```bash +docker-compose up -d redis +``` 2 - Open your Laravel's `.env` file and set the `REDIS_HOST` to your `Docker-IP` instead of the default `127.0.0.1` IP. @@ -555,7 +558,7 @@ CACHE_DRIVER=redis SESSION_DRIVER=redis ``` -4 - Finally make sure you have the `predis/predis` package `(~1.0)` installed via Composer first. +4 - Finally make sure you have the `predis/predis` package `(~1.0)` installed via Composer: ```bash composer require predis/predis:^1.0 @@ -571,6 +574,59 @@ composer require predis/predis:^1.0 +
+ +### Use Mongo + +1 - First make sure you run the MongoDB Container (`mongo`) with the `docker-compose up` command. + +```bash +docker-compose up -d mongo +``` + + +2 - Add the MongoDB configurations to the `config/database.php` config file: + +```php +'connections' => [ + + 'mongodb' => [ + 'driver' => 'mongodb', + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', 27017), + 'database' => env('DB_DATABASE', 'database'), + 'username' => '', + 'password' => '', + 'options' => [ + 'database' => '', + ] + ], + + // ... + +], +``` + +3 - Open your Laravel's `.env` file and update the following variables: + +- set the `DB_HOST` to your `Docker-IP`. +- set the `DB_PORT` to `27017`. +- set the `DB_DATABASE` to `database`. + + +4 - Finally make sure you have the `jenssegers/mongodb` package installed via Composer and its Service Provider is added. + +```bash +composer require jenssegers/mongodb +``` +More details about this [here](https://github.com/jenssegers/laravel-mongodb#installation). + +5 - Test it: + +- First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent). +- Enter the Workspace Continer `docker exec -it laradock_workspace_1 bash`. +- Migrate the Database `php artisan migrate`. +