<p>LaraDock strives to make the PHP development experience easier and faster.</p>
<p>It contains pre-packaged Docker Images that provides you a wonderful <em>development</em> environment without requiring you to install PHP, NGINX, MySQL, Redis, and any other software on your machines.</p>
<p>LaraDock is configured to run Laravel Apps by default, and it can be modified to run all kinds of PHP Apps (Symfony, CodeIgniter, WordPress, Drupal…).</p>
<h2id="quick-overview">Quick Overview</h2>
<p>Let’s see how easy it is to install <code>NGINX</code>, <code>PHP</code>, <code>Composer</code>, <code>MySQL</code>, <code>Redis</code> and <code>beanstalkd</code>:</p>
<p>1 - Clone LaraDock inside your PHP project:</p>
<p><ahref="https://www.docker.com">Docker</a> is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of <ahref="https://en.wikipedia.org/wiki/Operating-system-level_virtualization">operating-system-level virtualization</a> on Linux, Mac OS and Windows.</p>
<p><aname="why-docker-not-vagrant"></a></p>
<h2id="why-docker-not-vagrant">Why Docker not Vagrant!?</h2>
<p><ahref="https://www.vagrantup.com">Vagrant</a> creates Virtual Machines in minutes while Docker creates Virtual Containers in seconds.</p>
<p>Instead of providing a full Virtual Machines, like you get with Vagrant, Docker provides you <strong>lightweight</strong> Virtual Containers, that share the same kernel and allow to safely execute independent processes.</p>
<p>In addition to the speed, Docker gives tons of features that cannot be achieved with Vagrant.</p>
<p>Most importantly Docker can run on Development and on Production (same environment everywhere). While Vagrant is designed for Development only, (so you have to re-provision your server on Production every time).</p>
<p><aname="laradock-vs-homestead"></a></p>
<h2id="laradock-vs-homestead-for-laravel-developers">LaraDock VS Homestead (For Laravel Developers)</h2>
<blockquote>
<p>LaraDock It’s like Laravel Homestead but for Docker instead of Vagrant.</p>
</blockquote>
<p>LaraDock and <ahref="https://laravel.com/docs/master/homestead">Homestead</a> both give you complete virtual development environments. (Without the need to install and configure every single software on your own Operating System).</p>
<ul>
<li><p>Homestead is a tool that controls Vagrant for you (using Homestead special commands). And Vagrant manages your Virtual Machine.</p></li>
<li><p>LaraDock is a tool that controls Docker for you (using Docker & Docker Compose official commands). And Docker manages your Virtual Containers.</p></li>
</ul>
<p>Running a virtual container is much faster than running a full virtual Machine. Thus <strong>LaraDock is much faster than Homestead</strong>.</p>
<p><aname="Demo"></a></p>
<h2id="demo-video">Demo Video</h2>
<p>What’s better than a <strong>Demo Video</strong>:</p>
<p><em>Note 1: If you are not yet using Git for your PHP project, you can use <code>git clone https://github.com/Laradock/laradock.git</code> instead.</em></p>
<p><em>Note 2: To keep track of your LaraDock changes, between your projects and also keep LaraDock updated. <ahref="#keep-tracking-LaraDock">Check this</a></em></p>
<p><em>Note 3: In this case the folder structure will be like this:</em></p>
<pre><code>- project1
- laradock
- project2
- laradock
</code></pre>
<h5id="a-2-setup-environment-first-then-create-project">A.2) Setup environment first then create project:</h5>
<p><em>(In case you don’t have a project, and you want to create your project inside the Docker environment)</em></p>
<p>1 - Clone this repository anywhere on your machine:</p>
<p>Note: In this case the folder structure will be like this:</p>
<pre><code>- projects
- laradock
- myProject
</code></pre>
<p>2 - Edit the <code>docker-compose.yml</code> file to map to your project directory once you have it (example: <code>- ../myProject:/var/www</code>).</p>
<p>3 - Stop and re-run your docker-compose command for the changes to take place.</p>
<pre><code>docker-compose stop && docker-compose up -d XXXX YYYY ZZZZ ....
</code></pre>
<h4id="b-setup-for-multiple-projects">B) Setup for Multiple Projects:</h4>
<p>1 - Clone this repository anywhere on your machine:</p>
<p>2 - Edit the <code>docker-compose.yml</code> file to map to your projects directories:</p>
<pre><code> applications:
image: tianon/true
volumes:
- ../project1/:/var/www/project1
- ../project2/:/var/www/project2
</code></pre>
<p>3 - You can access all sites by visiting <code>http://localhost/project1/public</code> and <code>http://localhost/project2/public</code> but of course that’s not very useful so let’s setup NGINX quickly.</p>
<p>4 - Go to <code>nginx/sites</code> and copy <code>sample.conf.example</code> to <code>project1.conf</code> then to <code>project2.conf</code></p>
<p>5 - Open the <code>project1.conf</code> file and edit the <code>server_name</code> and the <code>root</code> as follow:</p>
<pre><code> server_name project1.dev;
root /var/www/project1/public;
</code></pre>
<p>Do the same for each project <code>project2.conf</code>, <code>project3.conf</code>,…</p>
<p>6 - Add the domains to the <strong>hosts</strong> files.</p>
<pre><code>127.0.0.1 project1.dev
</code></pre>
<p>7 - Create your project Databases. Right now you have to do it manually by entering your DB container, until we automate it soon.</p>
<h2id="usage">Usage</h2>
<p><strong>Read Before starting:</strong></p>
<p>If you are using <strong>Docker Toolbox</strong> (VM), do one of the following:</p>
<ul>
<li>Upgrade to Docker <ahref="https://www.docker.com/products/docker">Native</a> for Mac/Windows (Recommended). Check out <ahref="#upgrading-laradock">Upgrading LaraDock</a></li>
<li>Use LaraDock v3.* (Visit the <code>LaraDock-ToolBox</code><ahref="https://github.com/laradock/laradock/tree/LaraDock-ToolBox">Branch</a>).</li>
</ul>
<p><br></p>
<blockquote>
<p><strong>Warning:</strong> If you used an older version of LaraDock it’s highly recommended to rebuild the containers you need to use <ahref="#Build-Re-build-Containers">see how you rebuild a container</a> in order to prevent errors as much as possible.</p>
</blockquote>
<p><br></p>
<p>1 - Run Containers: <em>(Make sure you are in the <code>laradock</code> folder before running the <code>docker-compose</code> commands).</em></p>
<p><strong>Example:</strong> Running NGINX and MySQL:</p>
<pre><codeclass="language-bash">docker-compose up -d nginx mysql
</code></pre>
<p><strong>Note</strong>: The <code>workspace</code> and <code>php-fpm</code> will run automatically in most of the cases, so no need to specify them in the <code>up</code> command. If you couldn’t find them running then you need specify them as follow: <code>docker-compose up -d nginx php-fpm mysql workspace</code>.</p>
<p>You can select your own combination of Containers form the list below:</p>
<p><strong>Note:</strong> You can add <code>--user=laradock</code> (example <code>docker-compose exec --user=laradock workspace bash</code>) to have files created as your host’s user. (you can change the PUID (User id) and PGID (group id) variables from the <code>docker-compose.yml</code>).</p>
<p><br>
3 - Edit your project configurations.</p>
<p>Open your <code>.env</code> file and set the <code>DB_HOST</code> to <code>mysql</code>:</p>
<pre><codeclass="language-env">DB_HOST=mysql
</code></pre>
<p><em>If you want to use Laravel and you don’t have it installed yet, see <ahref="#Install-Laravel">How to Install Laravel in a Docker Container</a>.</em></p>
<p><br>
4 - Open your browser and visit your localhost address (<code>http://localhost/</code>).</p>
<p><br>
<strong>Debugging</strong>: if you are facing any problem here check the <ahref="#debugging">Debugging</a> section.</p>
<p>If you need a special support. Contact me, more details in the <ahref="#Help">Help & Questions</a> section.</p>
<p>You might use the <code>--no-cache</code> option if you want full rebuilding (<code>docker-compose build --no-cache {container-name}</code>).</p>
<p><br>
<aname="Add-Docker-Images"></a></p>
<h2id="add-more-software-docker-images">Add more Software (Docker Images)</h2>
<p>To add an image (software), just edit the <code>docker-compose.yml</code> and add your container details, to do so you need to be familiar with the <ahref="https://docs.docker.com/compose/compose-file/">docker compose file syntax</a>.</p>
<p><br>
<aname="View-the-Log-files"></a></p>
<h2id="view-the-log-files">View the Log files</h2>
<p>The NGINX Log file is stored in the <code>logs/nginx</code> directory.</p>
<p>However to view the logs of all the other containers (MySQL, PHP-FPM,…) you can run this:</p>
<p>Before installing PHP extensions, you have to decide whether you need for the <code>FPM</code> or <code>CLI</code> because each lives on a different container, if you need it for both you have to edit both containers.</p>
<p>The PHP-FPM extensions should be installed in <code>php-fpm/Dockerfile-XX</code>. <em>(replace XX with your default PHP version number)</em>.
<br>
The PHP-CLI extensions should be installed in <code>workspace/Dockerfile</code>.</p>
<p><br>
<aname="Change-the-PHP-FPM-Version"></a></p>
<h2id="change-the-php-fpm-version">Change the (PHP-FPM) Version</h2>
<p>By default <strong>PHP-FPM 7.0</strong> is running.</p>
<blockquote>
<p>The PHP-FPM is responsible of serving your application code, you don’t have to change the PHP-CLI version if you are planning to run your application on different PHP-FPM version.</p>
</blockquote>
<h3id="a-switch-from-php-7-0-to-php-5-6">A) Switch from PHP <code>7.0</code> to PHP <code>5.6</code></h3>
<p>1 - Open the <code>docker-compose.yml</code>.</p>
<p>2 - Search for <code>Dockerfile-70</code> in the PHP container section.</p>
<p>3 - Change the version number, by replacing <code>Dockerfile-70</code> with <code>Dockerfile-56</code>, like this:</p>
<p>3 - Rename <code>Dockerfile-56</code> to <code>Dockerfile-55</code>.</p>
<p>3 - Edit the file <code>FROM php:5.6-fpm</code> to <code>FROM php:5.5-fpm</code>.</p>
<p>4 - Build an image from <code>Dockerfile-55</code>.</p>
<p>5 - Open the <code>docker-compose.yml</code> file.</p>
<p>6 - Point <code>php-fpm</code> to your <code>Dockerfile-55</code> file.</p>
<p><br>
<aname="Change-the-PHP-CLI-Version"></a></p>
<h2id="change-the-php-cli-version">Change the PHP-CLI Version</h2>
<p>By default <strong>PHP-CLI 7.0</strong> is running.</p>
<blockquote>
<p>Note: it’s not very essential to edit the PHP-CLI version. The PHP-CLI is only used for the Artisan Commands & Composer. It doesn’t serve your Application code, this is the PHP-FPM job.</p>
</blockquote>
<p>The PHP-CLI is installed in the Workspace container. To change the PHP-CLI version you need to edit the <code>workspace/Dockerfile</code>.</p>
<p>Right now you have to manually edit the <code>Dockerfile</code> or create a new one like it’s done for the PHP-FPM. (consider contributing).</p>
<p><br>
<aname="Install-xDebug"></a></p>
<h2id="install-xdebug">Install xDebug</h2>
<p>1 - First install <code>xDebug</code> in the Workspace and the PHP-FPM Containers:
<br>
a) open the <code>docker-compose.yml</code> file
<br>
b) search for the <code>INSTALL_XDEBUG</code> argument under the Workspace Container
<br>
c) set it to <code>true</code>
<br>
d) search for the <code>INSTALL_XDEBUG</code> argument under the PHP-FPM Container
<br>
e) set it to <code>true</code></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- INSTALL_XDEBUG=true
...
php-fpm:
build:
context: ./php-fpm
args:
- INSTALL_XDEBUG=true
...
</code></pre>
<p>2 - Re-build the containers <code>docker-compose build workspace php-fpm</code></p>
<p>3 - Open <code>laradock/workspace/xdebug.ini</code> and/or <code>laradock/php-fpm/xdebug.ini</code> and enable at least the following configurations:</p>
<pre><code>xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_connect_back=1
</code></pre>
<p>For information on how to configure xDebug with your IDE and work it out, check this <ahref="https://github.com/LarryEitel/laravel-laradock-phpstorm">Repository</a>.</p>
<p><br>
<aname="Control-xDebug"></a></p>
<h2id="start-stop-xdebug">Start/Stop xDebug:</h2>
<p>By installing xDebug, you are enabling it to run on startup by default.</p>
<p>To control the behavior of xDebug (in the <code>php-fpm</code> Container), you can run the following commands from the LaraDock root folder, (at the same prompt where you run docker-compose):</p>
<ul>
<li>Stop xDebug from running by default: <code>./xdebugPhpFpm stop</code>.</li>
<li>Start xDebug by default: <code>./xdebugPhpFpm start</code>.</li>
<li>See the status: <code>./xdebugPhpFpm status</code>.</li>
</ul>
<p>Note: If <code>./xdebugPhpFpm</code> doesn’t execute and gives <code>Permission Denied</code> error the problem can be that file <code>xdebugPhpFpm</code> doesn’t have execution access. This can be fixed by running <code>chmod</code> command with desired access permissions.</p>
<p><br>
<aname="Install-Deployer"></a></p>
<h2id="install-deployer-deployment-tool-for-php">Install Deployer (Deployment tool for PHP)</h2>
<p>1 - Open the <code>docker-compose.yml</code> file
<br>
2 - Search for the <code>INSTALL_DEPLOYER</code> argument under the Workspace Container
<br>
3 - Set it to <code>true</code>
<br></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- INSTALL_DEPLOYER=true
...
</code></pre>
<p>4 - Re-build the containers <code>docker-compose build workspace</code></p>
<h2id="prepare-laradock-for-production">Prepare LaraDock for Production</h2>
<p>It’s recommended for production to create a custom <code>docker-compose.yml</code> file. For that reason, LaraDock is shipped with <code>production-docker-compose.yml</code> which should contain only the containers you are planning to run on production (usage example: <code>docker-compose -f production-docker-compose.yml up -d nginx mysql redis ...</code>).</p>
<p>Note: The Database (MySQL/MariaDB/…) ports should not be forwarded on production, because Docker will automatically publish the port on the host, which is quite insecure, unless specifically told not to. So make sure to remove these lines:</p>
<pre><code>ports:
- "3306:3306"
</code></pre>
<p>To learn more about how Docker publishes ports, please read <ahref="https://fralef.me/docker-and-iptables.html">this excellent post on the subject</a>.</p>
<p><br>
<aname="Digital-Ocean"></a></p>
<h2id="setup-laravel-and-docker-on-digital-ocean">Setup Laravel and Docker on Digital Ocean</h2>
<p>We recommend using <code>composer create-project</code> instead of the Laravel installer, to install Laravel.</p>
</blockquote>
<p>For more about the Laravel installation click <ahref="https://laravel.com/docs/master#installing-laravel">here</a>.</p>
<p>3 - Edit <code>docker-compose.yml</code> to Map the new application path:</p>
<p>By default, LaraDock assumes the Laravel application is living in the parent directory of the laradock folder.</p>
<p>Since the new Laravel application is in the <code>my-cool-app</code> folder, we need to replace <code>../:/var/www</code> with <code>../my-cool-app/:/var/www</code>, as follow:</p>
<pre><codeclass="language-yaml"> application:
image: tianon/true
volumes:
- ../my-cool-app/:/var/www
...
</code></pre>
<p>4 - Go to that folder and start working..</p>
<pre><codeclass="language-bash">cd my-cool-app
</code></pre>
<p>5 - Go back to the LaraDock installation steps to see how to edit the <code>.env</code> file.</p>
<p>Add <code>--user=laradock</code> (example <code>docker-compose exec --user=laradock workspace bash</code>) to have files created as your host’s user.</p>
<p>1 - First add <code>php-worker</code> container. It will be similar as like PHP-FPM Container.
<br>
a) open the <code>docker-compose.yml</code> file
<br>
b) add a new service container by simply copy-paste this section below PHP-FPM container</p>
<pre><codeclass="language-yaml"> php-worker:
build:
context: ./php-fpm
dockerfile: Dockerfile-70 # or Dockerfile-56, choose your PHP-FPM container setting
volumes_from:
- applications
command: php artisan queue:work
</code></pre>
<p>2 - Start everything up</p>
<pre><codeclass="language-bash">docker-compose up -d php-worker
</code></pre>
<p><br>
<aname="Use-Redis"></a></p>
<h2id="use-redis">Use Redis</h2>
<p>1 - First make sure you run the Redis Container (<code>redis</code>) with the <code>docker-compose up</code> command.</p>
<pre><codeclass="language-bash">docker-compose up -d redis
</code></pre>
<p>2 - Open your Laravel’s <code>.env</code> file and set the <code>REDIS_HOST</code> to <code>redis</code></p>
<pre><codeclass="language-env">REDIS_HOST=redis
</code></pre>
<p>If you don’t find the <code>REDIS_HOST</code> variable in your <code>.env</code> file. Go to the database configuration file <code>config/database.php</code> and replace the default <code>127.0.0.1</code> IP with <code>redis</code> for Redis like this:</p>
<pre><codeclass="language-php">'redis' => [
'cluster' => false,
'default' => [
'host' => 'redis',
'port' => 6379,
'database' => 0,
],
],
</code></pre>
<p>3 - To enable Redis Caching and/or for Sessions Management. Also from the <code>.env</code> file set <code>CACHE_DRIVER</code> and <code>SESSION_DRIVER</code> to <code>redis</code> instead of the default <code>file</code>.</p>
<pre><codeclass="language-env">CACHE_DRIVER=redis
SESSION_DRIVER=redis
</code></pre>
<p>4 - Finally make sure you have the <code>predis/predis</code> package <code>(~1.0)</code> installed via Composer:</p>
<p>More details about this <ahref="https://github.com/jenssegers/laravel-mongodb#installation">here</a>.</p>
<p>7 - Test it:</p>
<ul>
<li>First let your Models extend from the Mongo Eloquent Model. Check the <ahref="https://github.com/jenssegers/laravel-mongodb#eloquent">documentation</a>.</li>
<li>Enter the Workspace Container.</li>
<li>Migrate the Database <code>php artisan migrate</code>.</li>
</ul>
<p><br>
<aname="Use-phpMyAdmin"></a></p>
<h2id="use-phpmyadmin">Use PhpMyAdmin</h2>
<p>1 - Run the phpMyAdmin Container (<code>phpmyadmin</code>) with the <code>docker-compose up</code> command. Example:</p>
<pre><codeclass="language-bash"># use with mysql
docker-compose up -d mysql phpmyadmin
# use with mariadb
docker-compose up -d mariadb phpmyadmin
</code></pre>
<p>2 - Open your browser and visit the localhost on port <strong>8080</strong>: <code>http://localhost:8080</code></p>
<p><br>
<aname="Use-pgAdmin"></a></p>
<h2id="use-pgadmin">Use PgAdmin</h2>
<p>1 - Run the pgAdmin Container (<code>pgadmin</code>) with the <code>docker-compose up</code> command. Example:</p>
<pre><codeclass="language-bash">docker-compose up -d postgres pgadmin
</code></pre>
<p>2 - Open your browser and visit the localhost on port <strong>5050</strong>: <code>http://localhost:5050</code></p>
<p><br>
<aname="Use-Beanstalkd"></a></p>
<h2id="use-beanstalkd">Use Beanstalkd</h2>
<p>1 - Run the Beanstalkd Container:</p>
<pre><codeclass="language-bash">docker-compose up -d beanstalkd
</code></pre>
<p>2 - Configure Laravel to connect to that container by editing the <code>config/queue.php</code> config file.</p>
<p>a. first set <code>beanstalkd</code> as default queue driver
b. set the queue host to beanstalkd : <code>QUEUE_HOST=beanstalkd</code></p>
<p><em>beanstalkd is now available on default port <code>11300</code>.</em></p>
<p>3 - Require the dependency package <ahref="https://github.com/pda/pheanstalk">pda/pheanstalk</a> using composer.</p>
<p>Optionally you can use the Beanstalkd Console Container to manage your Queues from a web interface.</p>
<p>1 - Run the Beanstalkd Console Container:</p>
<pre><codeclass="language-bash">docker-compose up -d beanstalkd-console
</code></pre>
<p>2 - Open your browser and visit <code>http://localhost:2080/</code></p>
<p>3 - Add the server</p>
<ul>
<li>Host: beanstalkd</li>
<li>Port: 11300</li>
</ul>
<p>4 - Done.</p>
<p><br>
<aname="Use-ElasticSearch"></a></p>
<h2id="use-elasticsearch">Use ElasticSearch</h2>
<p>1 - Run the ElasticSearch Container (<code>elasticsearch</code>) with the <code>docker-compose up</code> command:</p>
<pre><codeclass="language-bash">docker-compose up -d elasticsearch
</code></pre>
<p>2 - Open your browser and visit the localhost on port <strong>9200</strong>: <code>http://localhost:9200</code></p>
<p>1 - Install the ElasticSearch plugin like <ahref="https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html">delete-by-query</a>.</p>
<p>1 - Run the Selenium Container (<code>selenium</code>) with the <code>docker-compose up</code> command. Example:</p>
<pre><codeclass="language-bash">docker-compose up -d selenium
</code></pre>
<p>2 - Open your browser and visit the localhost on port <strong>4444</strong> at the following URL: <code>http://localhost:4444/wd/hub</code></p>
<p><br>
<aname="Use-RethinkDB"></a></p>
<h2id="use-rethinkdb">Use RethinkDB</h2>
<p>The RethinkDB is an open-source Database for Real-time Web (<ahref="https://rethinkdb.com/">RethinkDB</a>).
A package (<ahref="https://github.com/duxet/laravel-rethinkdb">Laravel RethinkDB</a>) is being developed and was released a version for Laravel 5.2 (experimental).</p>
<p>1 - Run the RethinkDB Container (<code>rethinkdb</code>) with the <code>docker-compose up</code> command.</p>
<pre><codeclass="language-bash">docker-compose up -d rethinkdb
</code></pre>
<p>2 - Access the RethinkDB Administration Console <ahref="http://localhost:8090/#tables">http://localhost:8090/#tables</a> for create a database called <code>database</code>.</p>
<p>3 - Add the RethinkDB configurations to the <code>config/database.php</code> configuration file:</p>
<p>To install CodeIgniter 3 on LaraDock all you have to do is the following simple steps:</p>
<p>1 - Open the <code>docker-compose.yml</code> file.</p>
<p>2 - Change <code>CODEIGNITER=false</code> to <code>CODEIGNITER=true</code>.</p>
<p>3 - Re-build your PHP-FPM Container <code>docker-compose build php-fpm</code>.</p>
<p><br>
<aname="Misc"></a></p>
<h2id="miscellaneous">Miscellaneous</h2>
<p><br>
<aname="Change-the-timezone"></a></p>
<h2id="change-the-timezone">Change the timezone</h2>
<p>To change the timezone for the <code>workspace</code> container, modify the <code>TZ</code> build argument in the Docker Compose file to one in the <ahref="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">TZ database</a>.</p>
<p>For example, if I want the timezone to be <code>New York</code>:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- TZ=America/New_York
...
</code></pre>
<p>We also recommend <ahref="http://www.camroncade.com/managing-timezones-with-laravel/">setting the timezone in Laravel</a>.</p>
<p><br>
<aname="CronJobs"></a></p>
<h2id="adding-cron-jobs">Adding cron jobs</h2>
<p>You can add your cron jobs to <code>workspace/crontab/root</code> after the <code>php artisan</code> line.</p>
<p>Make sure you <ahref="#Change-the-timezone">change the timezone</a> if you don’t want to use the default (UTC).</p>
<p><br>
<aname="Workspace-ssh"></a></p>
<h2id="access-workspace-via-ssh">Access workspace via ssh</h2>
<p>You can access the <code>workspace</code> container through <code>localhost:2222</code> by setting the <code>INSTALL_WORKSPACE_SSH</code> build argument to <code>true</code>.</p>
<p>To change the default forwarded port for ssh:</p>
<pre><codeclass="language-yml"> workspace:
ports:
- "2222:22" # Edit this line
...
</code></pre>
<p><br>
<aname="MySQL-access-from-host"></a></p>
<h2id="mysql-access-from-host">MySQL access from host</h2>
<p>You can forward the MySQL/MariaDB port to your host by making sure these lines are added to the <code>mysql</code> or <code>mariadb</code> section of the <code>docker-compose.yml</code> or in your <ahref="https://docs.docker.com/compose/extends/">environment specific Compose</a> file.</p>
<pre><code>ports:
- "3306:3306"
</code></pre>
<p><br>
<aname="MySQL-root-access"></a></p>
<h2id="mysql-root-access">MySQL root access</h2>
<p>The default username and password for the root MySQL user are <code>root</code> and <code>root</code>.</p>
<p>1 - Enter the MySQL container: <code>docker-compose exec mysql bash</code>.</p>
<p>2 - Enter mysql: <code>mysql -uroot -proot</code> for non root access use <code>mysql -uhomestead -psecret</code>.</p>
<p>3 - See all users: <code>SELECT User FROM mysql.user;</code></p>
<p>4 - Run any commands <code>show databases</code>, <code>show tables</code>, <code>select * from.....</code>.</p>
<p><br>
<aname="Change-MySQL-port"></a></p>
<h2id="change-mysql-port">Change MySQL port</h2>
<p>Modify the <code>mysql/my.cnf</code> file to set your port number, <code>1234</code> is used as an example.</p>
<pre><code>[mysqld]
port=1234
</code></pre>
<p>If you need <ahref="#MySQL-access-from-host">MySQL access from your host</a>, do not forget to change the internal port number (<code>"3306:3306"</code> -><code>"3306:1234"</code>) in the docker-compose configuration file.</p>
<p><br>
<aname="Use-custom-Domain"></a></p>
<h2id="use-custom-domain-instead-of-the-docker-ip">Use custom Domain (instead of the Docker IP)</h2>
<p>Assuming your custom domain is <code>laravel.dev</code></p>
<p>1 - Open your <code>/etc/hosts</code> file and map your localhost address <code>127.0.0.1</code> to the <code>laravel.dev</code> domain, by adding the following:</p>
<h2id="enable-global-composer-build-install">Enable Global Composer Build Install</h2>
<p>Enabling Global Composer Install during the build for the container allows you to get your composer requirements installed and available in the container after the build is done.</p>
<p>1 - Open the <code>docker-compose.yml</code> file</p>
<p>2 - Search for the <code>COMPOSER_GLOBAL_INSTALL</code> argument under the Workspace Container and set it to <code>true</code></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- COMPOSER_GLOBAL_INSTALL=true
...
</code></pre>
<p>3 - Now add your dependencies to <code>workspace/composer.json</code></p>
<p>4 - Re-build the Workspace Container <code>docker-compose build workspace</code></p>
<p><ahref="https://github.com/hirak/prestissimo">Prestissimo</a> is a plugin for composer which enables parallel install functionality.</p>
<p>1 - Enable Running Global Composer Install during the Build:</p>
<p>Click on this <ahref="#Enable-Global-Composer-Build-Install">Enable Global Composer Build Install</a> and do steps 1 and 2 only then continue here.</p>
<p>2 - Add prestissimo as requirement in Composer:</p>
<p>a - Now open the <code>workspace/composer.json</code> file</p>
<p>b - Add <code>"hirak/prestissimo": "^0.3"</code> as requirement</p>
<p>c - Re-build the Workspace Container <code>docker-compose build workspace</code></p>
<p><br>
<aname="Install-Node"></a></p>
<h2id="install-node-nvm">Install Node + NVM</h2>
<p>To install NVM and NodeJS in the Workspace container</p>
<p>1 - Open the <code>docker-compose.yml</code> file</p>
<p>2 - Search for the <code>INSTALL_NODE</code> argument under the Workspace Container and set it to <code>true</code></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- INSTALL_NODE=true
...
</code></pre>
<p>3 - Re-build the container <code>docker-compose build workspace</code></p>
<p>Yarn is a new package manager for JavaScript. It is so faster than npm, which you can find <ahref="http://yarnpkg.com/en/compare">here</a>.To install NodeJS and <ahref="https://yarnpkg.com/">Yarn</a> in the Workspace container:</p>
<p>1 - Open the <code>docker-compose.yml</code> file</p>
<p>2 - Search for the <code>INSTALL_NODE</code> and <code>INSTALL_YARN</code> argument under the Workspace Container and set it to <code>true</code></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- INSTALL_NODE=true
- INSTALL_YARN=true
...
</code></pre>
<p>3 - Re-build the container <code>docker-compose build workspace</code></p>
<p><br>
<aname="Install-Linuxbrew"></a></p>
<h2id="install-linuxbrew">Install Linuxbrew</h2>
<p>Linuxbrew is a package manager for Linux. It is the Linux version of MacOS Homebrew and can be found <ahref="http://linuxbrew.sh">here</a>. To install Linuxbrew in the Workspace container:</p>
<p>1 - Open the <code>docker-compose.yml</code> file</p>
<p>2 - Search for the <code>INSTALL_LINUXBREW</code> argument under the Workspace Container and set it to <code>true</code></p>
<p>It should be like this:</p>
<pre><codeclass="language-yml"> workspace:
build:
context: ./workspace
args:
- INSTALL_LINUXBREW=true
...
</code></pre>
<p>3 - Re-build the container <code>docker-compose build workspace</code></p>
<p>When you start your docker container, LaraDock will copy the <code>aliases.sh</code> file located in the <code>laradock/workspace</code> directory and add sourcing to the container <code>~/.bashrc</code> file.</p>
<p>You are free to modify the <code>aliases.sh</code> as you see fit, adding your own aliases (or function macros) to suit your requirements.</p>
<p>Moving from Docker Toolbox (VirtualBox) to Docker Native (for Mac/Windows). Requires upgrading LaraDock from v3.* to v4.*:</p>
<ol>
<li>Stop the docker VM <code>docker-machine stop {default}</code></li>
<li>Install Docker for <ahref="https://docs.docker.com/docker-for-mac/">Mac</a> or <ahref="https://docs.docker.com/docker-for-windows/">Windows</a>.</li>
<li>Upgrade LaraDock to <code>v4.*.*</code> (<code>git pull origin master</code>)</li>
<li>Use LaraDock as you used to do: <code>docker-compose up -d nginx mysql</code>.</li>
</ol>
<p><strong>Note:</strong> If you face any problem with the last step above: rebuild all your containers
<code>docker-compose build --no-cache</code>
“Warning Containers Data might be lost!”</p>
<p><br>
<aname="Speed-MacOS"></a></p>
<h2id="improve-speed-on-macos">Improve speed on MacOS</h2>
<p>Sharing code into Docker containers with osxfs have very poor performance compared to Linux. You can get around this issue by using NFS to share your files betwen your host and your container.</p>
<blockquote>
<p>How to share files using NFS (d4m-nfs)</p>
</blockquote>
<p><ahref="https://github.com/IFSight/d4m-nfs">d4m-nfs</a> automatically mount NFS volume instead of osxfs one.</p>
<p>1) Update the Docker [File Sharing] preferences:</p>
<p>Click on the Docker Icon > Preferences > (remove everything form the list except <code>/tmp</code>).</p>
<p>2) Restart Docker.</p>
<p>3) Clone the <ahref="https://github.com/IFSight/d4m-nfs">d4m-nfs</a> repository to your <code>home</code> directory.</p>
<p>4) Create (or edit) the file <code>~/d4m-nfs/etc/d4m-nfs-mounts.txt</code>, and write the follwing configuration in it:</p>
<pre><codeclass="language-txt">/Users:/Users
/Volumes:/Volumes
/private:/private
</code></pre>
<p>5) Create (or edit) the file <code>/etc/exports</code>, make sure it exists and is empty. (There may be collisions if you come from Vagrant or if you already executed the <code>d4m-nfs.sh</code> script before).</p>
<p>That’s it! Run your containers.. Example:</p>
<pre><codeclass="language-bash">docker-compose up -d nginx mysql
</code></pre>
<p><strong>Note:</strong> If you faced any errors, try restarting Docker, and make sure you have no spaces in the <code>d4m-nfs-mounts.txt</code> file, and your <code>/etc/exports</code> file is clear.</p>
<p><br>
<aname="Common-Problems"></a></p>
<h2id="common-problems">Common Problems</h2>
<p><em>Here’s a list of the common problems you might face, and the possible solutions.</em></p>
<p><br></p>
<h2id="i-see-a-blank-white-page-instead-of-the-laravel-welcome-page">I see a blank (white) page instead of the Laravel ‘Welcome’ page!</h2>
<p>Run the following command from the Laravel root directory:</p>
<h2id="i-see-welcome-to-nginx-instead-of-the-laravel-app">I see “Welcome to nginx” instead of the Laravel App!</h2>
<p>Use <code>http://127.0.0.1</code> instead of <code>http://localhost</code> in your browser.</p>
<p><br></p>
<h2id="i-see-an-error-message-containing-address-already-in-use-or-port-is-already-allocated">I see an error message containing <code>address already in use</code> or <code>port is already allocated</code></h2>
<p>Make sure the ports for the services that you are trying to run (22, 80, 443, 3306, etc.) are not being used already by other programs on the host, such as a built in <code>apache</code>/<code>httpd</code> service or other development tools you have installed.</p>
<p><br></p>
<h2id="i-get-nginx-error-404-not-found-on-windows">I get NGINX error 404 Not Found on Windows.</h2>
<ol>
<li>Go to docker Settings on your Windows machine.</li>
<li>Click on the <code>Shared Drives</code> tab and check the drive that contains your project files.</li>
<li>Enter your windows username and password.</li>
<li>Go to the <code>reset</code> tab and click restart docker.</li>
</ol>
<p><br></p>
<h2id="the-time-in-my-services-does-not-match-the-current-time">The time in my services does not match the current time</h2>
<ol>
<li>Make sure you’ve <ahref="#Change-the-timezone">changed the timezone</a>.</li>
<li>Stop and rebuild the containers (<code>docker-compose up -d --build <services></code>)</li>
</ol>
<p><br></p>
<h2id="i-get-mysql-connection-refused">I get MySQL connection refused</h2>
<p>This error sometimes happens because your Laravel application isn’t running on the container localhost IP (Which is 127.0.0.1). Steps to fix it:</p>
<ul>
<li>Option A
<ol>
<li>Check your running Laravel application IP by dumping <code>Request::ip()</code> variable using <code>dd(Request::ip())</code> anywhere on your application. The result is the IP of your Laravel container.</li>
<li>Change the <code>DB_HOST</code> variable on env with the IP that you received from previous step.</li>
</ol></li>
<li>Option B
<ol>
<li>Change the <code>DB_HOST</code> value to the same name as the MySQL docker container. The LaraDock docker-compose file currently has this as <code>mysql</code></li>
</ol></li>
</ul>
<h1>Related Projects </h1>
<p>LaraDock related projects:</p>
<ul>
<li><ahref="https://github.com/lorinlee/laradock-cli">LaraDock CLI</a> by <ahref="https://github.com/lorinlee">LorinLee</a></li>
<li><ahref="https://github.com/bagart/laradock_env">LaraDock Env</a> by <ahref="https://github.com/bagart">BAGArt</a></li>
<li><ahref="https://github.com/poyhsiao/Klaradock">Klaradock</a> by <ahref="https://github.com/poyhsiao">Kim Hsiao</a></li>
<li><ahref="https://github.com/sifat-rahim/ansible-laradock-kubernetes">Ansible Laradock Kubernetes</a> by <ahref="https://github.com/sifat-rahim">Sifat Rahim</a>
These Docker Compose projects have piqued our interest:</li>
<li><ahref="https://github.com/ojhaujjwal/magedock">MageDock</a> by <ahref="https://github.com/ojhaujjwal">Ujjwal Ojha</a></li>
<li><ahref="https://github.com/scudelletti/rubydev-dock">RubyDev-Dock</a> by <ahref="https://github.com/scudelletti">Diogo Scudelletti</a></li>
<li><ahref="https://github.com/Osedea/nodock">NoDock</a> by <ahref="https://github.com/Osedea">Osedea</a></li>
</ul>
<p>If you want your project listed here, please open an issue.</p>
<h1>Help & Questions </h1>
<p>Join the chat room on <ahref="https://gitter.im/LaraDock/laradock">Gitter</a> and get help and support from the community.</p>
<p>You can as well can open an <ahref="https://github.com/laradock/laradock/issues">issue</a> on Github (will be labeled as Question) and discuss it with people on <ahref="https://gitter.im/LaraDock/laradock">Gitter</a>.</p>
<h1>Contributing </h1>
<p>Your contribution is more than welcome.</p>
<h2id="got-a-question-or-problem">Got a Question or Problem?</h2>
<p>If you have questions about how to use LaraDock, please direct your questions to the discussion on <ahref="https://gitter.im/LaraDock/laradock">Gitter</a>. If you believe your question could help others, then consider opening an <ahref="https://github.com/laradock/laradock/issues">Issue</a> (it will be labeled as Question).</p>
<h2id="found-an-issue">Found an Issue?</h2>
<p>If you find a bug in the source code or a mistake in the documentation, you can help us by
submitting an <ahref="https://github.com/laradock/laradock/issues">Issue</a>. Even better you can submit a Pull Request with a fix.</p>
<h2id="want-a-feature">Want a Feature?</h2>
<p>You can request a new feature by submitting an <ahref="https://github.com/laradock/laradock/issues">Issue</a> (it will be labeled as Feature Suggestion). If you would like to implement a new feature then consider submitting a Pull Request.</p>
<h2id="edit-the-documentation">Edit the documentation</h2>
<p>Laradock uses <ahref="https://gohugo.io/">Hugo</a> as website generator tool, with the <ahref="http://themes.gohugo.io/theme/material-docs/">Material Docs theme</a>. You might need to check their docs quickly.</p>
<ol>
<li>Install <ahref="https://gohugo.io/">Hugo</a> on your machine.</li>
<li>Clone laradock.</li>
<li>Go to <code>/docs</code>.</li>
<li>Delete everything except the <code>_settings</code> folder & the <code>CNAME</code> file.</li>
<li>Open <code>docs/_settings</code> from your terminal and run <code>hugo serve</code> to host the website locally.</li>
<li>Open the <code>docs/_settings/content</code> and search for the folder of the section you want to edit.</li>
<li>In each secion there’s an <code>index.md</code> file, that’s the file you need to edit.</li>
<li>To edit the sidebar (in case you are adding new section) go to <code>docs/_settings/config.toml</code> and add the section there.</li>
<li>After done editing, run the this command <code>hugo</code> to generate the updated site inside the <code>docs</code> folder.</li>
<li>Go back to the project root directory, commit and push..</li>
</ol>
<h2id="coding-guidelines">Coding Guidelines</h2>
<h2id="support-new-software">Support new Software</h2>
<ul>
<li><p>Create folder with the software name.</p></li>
<li><p>Add a <code>Dockerfile</code>, write your code there.</p></li>
<li><p>You may add additional files in the software folder.</p></li>
<li><p>Add the software to the <code>docker-compose.yml</code> file.</p></li>
<li><p>Make sure you follow our commenting style.</p></li>
<li><p>Add the software in the <code>Readme</code>.</p></li>
<h2id="submitting-an-issue">Submitting an Issue</h2>
<p>Before you submit your issue search the archive, maybe your question was already answered.</p>
<p>If your issue appears to be a bug, and hasn’t been reported, open a new issue.
Help us to maximize the effort we can spend fixing issues and adding new
features, by not reporting duplicate issues.</p>
<h2id="before-submitting-a-pull-request-pr">Before Submitting a Pull Request (PR)</h2>
<p>Always Test everything and make sure its working:</p>
<ul>
<li>Pull the latest updates (or fork of you don’t have permission)</li>
<li>Before editing anything:
<ul>
<li>Test building the container (docker-compose build –no-cache container-name) build with no cache first.</li>
<li>Test running the container with some other containers in real app and see of everything is working fine.</li>
</ul></li>
<li>Now edit the container (edit section by section and test rebuilding the container after every edited section)
<ul>
<li>Testing building the container (docker-compose build container-name) with no errors.</li>
<li>Test it in real App.</li>
</ul></li>
</ul>
<h2id="submitting-a-pr">Submitting a PR</h2>
<p>Consider the following guidelines:</p>
<ul>
<li><p>Search <ahref="https://github.com/laradock/laradock/pulls">GitHub</a> for an open or closed Pull Request that relates to your submission. You don’t want to duplicate effort.</p></li>
<li><p>In GitHub, send a pull request to <code>laradock:master</code>.</p></li>
<li><p>If we suggest changes then:</p>
<ul>
<li>Make the required updates.</li>
<li>Commit your changes to your branch (e.g. <code>my-fix-branch</code>).</li>
<li>Push the changes to your GitHub repository (this will update your Pull Request).</li>
</ul></li>
</ul>
<blockquote>
<p>If the PR gets too outdated we may ask you to rebase and force push to update the PR:</p>
</blockquote>
<pre><codeclass="language-shell">git rebase master -i
git push origin my-fix-branch -f
</code></pre>
<p><em>WARNING. Squashing or reverting commits and forced push thereafter may remove GitHub comments on code that were previously made by you and others in your commits.</em></p>
<h2id="after-your-pr-is-merged">After your PR is merged</h2>
<p>After your pull request is merged, you can safely delete your branch and pull the changes
from the main (upstream) repository:</p>
<ul>
<li><p>Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:</p>