Compare commits

...

12 Commits

5 changed files with 191 additions and 160 deletions

231
README.md
View File

@ -19,7 +19,7 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
- [Intro](#Intro) - [Intro](#Intro)
- [Features](#features) - [Features](#features)
- [Supported Containers](#Supported-Containers) - [Supported Software's](#Supported-Containers)
- [What is Docker](#what-is-docker) - [What is Docker](#what-is-docker)
- [What is Laravel](#what-is-laravel) - [What is Laravel](#what-is-laravel)
- [Why Docker not Vagrant](#why-docker-not-vagrant) - [Why Docker not Vagrant](#why-docker-not-vagrant)
@ -50,13 +50,12 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
- [Change the PHP-CLI Version](#Change-the-PHP-CLI-Version) - [Change the PHP-CLI Version](#Change-the-PHP-CLI-Version)
- [Install xDebug](#Install-xDebug) - [Install xDebug](#Install-xDebug)
- [Misc](#Misc) - [Misc](#Misc)
- [Run a Docker Virtual Host](#Run-Docker-Virtual-Host)
- [Find your Docker IP Address](#Find-Docker-IP-Address)
- [Use custom Domain](#Use-custom-Domain) - [Use custom Domain](#Use-custom-Domain)
- [Enable Global Composer Build Install](#Enable-Global-Composer-Build-Install) - [Enable Global Composer Build Install](#Enable-Global-Composer-Build-Install)
- [Install Prestissimo](#Install-Prestissimo) - [Install Prestissimo](#Install-Prestissimo)
- [Install Node + NVM](#Install-Node) - [Install Node + NVM](#Install-Node)
- [Debugging](#debugging) - [Debugging](#debugging)
- [Upgrading Docker](#upgrading)
- [Help & Questions](#Help) - [Help & Questions](#Help)
@ -93,25 +92,31 @@ docker-compose up nginx mysql redis
<a name="Supported-Containers"></a> <a name="Supported-Containers"></a>
### Supported Containers ### Supported Software's (Containers)
- PHP-FPM - **Database Engines:**
- NGINX
- HHVM
- MySQL - MySQL
- PostgreSQL - PostgreSQL
- MariaDB - MariaDB
- MongoDB - MongoDB
- Neo4j - Neo4j
- **Cache Engines:**
- Redis - Redis
- Memcached - Memcached
- **PHP Servers:**
- NGINX
- Apache2
- Caddy - Caddy
- Beanstalkd - **PHP Compilers:**
- Beanstalkd Console - PHP-FPM
- Workspace (contains: Composer, PHP7-CLI, Laravel Installer, Git, Node, Gulp, SQLite, Vim, Nano, cURL...) - HHVM
- **Message Queueing Systems:**
- Beanstalkd (+ Beanstalkd Console)
- **Tools:**
- Workspace (PHP7-CLI, Composer, Git, Node, Gulp, SQLite, Vim, Nano, cURL...)
>If you can't find your container, build it yourself and add it to this list. Contributions are welcomed :) >If you can't find your Software, build it yourself and add it to this list. Contributions are welcomed :)
@ -153,20 +158,27 @@ Running a virtual Container is much faster than running a full virtual Machine.
<a name="Requirements"></a>
## Requirements
| Linux | Windows & MAC |
|--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [Laravel](https://laravel.com/docs/master/installation) | [Laravel](https://laravel.com/docs/master/installation) |
| [Git](https://git-scm.com/downloads) | [Git](https://git-scm.com/downloads) |
| [Docker Engine](https://docs.docker.com/engine/installation/linux/ubuntulinux) | [Docker Toolbox](https://www.docker.com/toolbox) OR [Native Docker](https://beta.docker.com/) |
| [Docker Compose](https://docs.docker.com/compose/install) | |
<a name="Demo"></a> <a name="Demo"></a>
## Demo Video ## Demo Video
What's better than a [**Demo Video**](https://www.youtube.com/watch?v=-DamFMczwDA) :) What's better than a **Demo Video**:
- LaraDock v4.0 (Coming soon..)
- LaraDock [v2.2](https://www.youtube.com/watch?v=-DamFMczwDA)
- LaraDock [v0.3](https://www.youtube.com/watch?v=jGkyO6Is_aI)
- LaraDock [v0.1](https://www.youtube.com/watch?v=3YQsHe6oF80)
<a name="Requirements"></a>
## Requirements
- [Git](https://git-scm.com/downloads)
- [Docker](https://www.docker.com/products/docker/)
<a name="Installation"></a> <a name="Installation"></a>
## Installation ## Installation
@ -193,13 +205,17 @@ git clone https://github.com/LaraDock/laradock.git
## Usage ## Usage
1 - For **Windows & MAC** users only: If you are not using the native Docker-Engine `Beta`, make sure you have a running Docker Virtual Host on your machine. >**Note:**
[How to run a Docker Virtual Host?](#Run-Docker-Virtual-Host) <br>
(**Linux** users don't need a Virtual Host, so skip this step). >LaraDock version 4 and above is customized only for **Docker Native** (For Mac/Windows).
<br>
>LaraDock version 3 and below is customized only for **Docker Toolbox** (VirtualBox VM). If you are still using the "Docker Toolbox" you might need to check the branch `LaraDock-ToolBox`.
<br> <br>
2 - Run some Containers: *(Make sure you are in the `laradock` folder before running the `docker-compose` commands).* 1 - Run Containers: *(Make sure you are in the `laradock` folder before running the `docker-compose` commands).*
@ -209,46 +225,43 @@ git clone https://github.com/LaraDock/laradock.git
docker-compose up -d nginx mysql docker-compose up -d nginx mysql
``` ```
You can select your own combination of container form this list: You can select your own combination of Containers form the list below:
`nginx`, `hhvm` ,`mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `mongo`, `memcached`, `beanstalkd`, `beanstalkd-console`, `caddy`, `workspace`, `php-fpm`. `nginx`, `hhvm`, `php-fpm`, `mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `mongo`, `apache2`, `caddy`, `memcached`, `beanstalkd`, `beanstalkd-console`, `workspace`.
**Note**: `workspace` and `php-fpm` will run automatically in most of the cases, so no need to specify them in the `up` command. **Note**: `workspace` and `php-fpm` will run automatically in most of the cases, so no need to specify them in the `up` command.
<br> <br>
3 - Enter the Workspace container, to execute commands like (Artisan, Composer, PHPUnit, Gulp, ...). 2 - Enter the Workspace container, to execute commands like (Artisan, Composer, PHPUnit, Gulp, ...).
```bash ```bash
docker exec -it {Workspace-Container-Name} bash docker-compose exec workspace bash
``` ```
Replace `{Workspace-Container-Name}` with your Workspace container name. <br />
<br> Add `--user=laradock` (example `docker-compose exec --user=laradock workspace bash`) to have files created as your host's user. (you can change the PUID (User id) and PGID (group id) variables from the `docker-compose.yml`).
To find the containers names type `docker-compose ps`.
<br> <br>
4 - Edit the Laravel configurations. 3 - Edit the Laravel configurations.
If you don't have a Laravel project installed yet, see [How to Install Laravel in a Docker Container](#Install-Laravel). If you don't have a Laravel project installed yet, see [How to Install Laravel in a Docker Container](#Install-Laravel).
Open your Laravel's `.env` file and set the `DB_HOST` to your `{Docker-IP}`: Open your Laravel's `.env` file and set the `DB_HOST` to your `mysql`:
```env ```env
DB_HOST=xxx.xxx.xxx.xxx DB_HOST=mysql
``` ```
[How to find my Docker IP Address?](#Find-Docker-IP-Address)
<br> <br>
5 - Open your browser and visit your `{Docker-IP}` address (`http://xxx.xxx.xxx.xxx`). 4 - Open your browser and visit your localhost address (`http://localhost/`).
@ -262,8 +275,6 @@ If you need a special support. Contact me, more details in the [Help & Questions
<a name="Documentation"></a> <a name="Documentation"></a>
## Documentation ## Documentation
**Note:** this documentation doesn't cover the Docker Beta *(Native Docker on MAC and Windows)*. However, the commands are very similar. We are planning to cover the Docker Beta soon.
<a name="Docker"></a> <a name="Docker"></a>
### [Docker] ### [Docker]
@ -327,8 +338,15 @@ docker-compose down
2 - enter any container using: 2 - enter any container using:
```bash ```bash
docker exec -it {container-name} bash docker-composer exec {container-name} bash
``` ```
*Example: enter MySQL container*
```bash
docker-compose exec mysql bash
```
3 - to exit a container, type `exit`. 3 - to exit a container, type `exit`.
@ -380,10 +398,7 @@ example for `mysql` it will be `mysql/Dockerfile`.
```bash ```bash
docker-compose build mysql docker-compose build mysql
``` ```
More info on Containers rebuilding [here](#Build-Re-build-Containers).
*If you find any bug or you have and suggestion that can improve the performance of any image, please consider contributing. Thanks in advance.*
@ -407,6 +422,7 @@ Optionally you can specify which container to rebuild (instead of rebuilding all
docker-compose build {container-name} docker-compose build {container-name}
``` ```
You might use the `--no-cache` option if you want full rebuilding (`docker-compose build --no-cache {container-name}`).
@ -484,6 +500,8 @@ Since the new Laravel application is in the `my-cool-app` folder, we need to rep
cd my-cool-app cd my-cool-app
``` ```
5 - Go back to the laraDock installation steps to see how to edit the `.env` file.
<br> <br>
@ -507,9 +525,12 @@ docker-compose ps
3 - Enter the Workspace container: 3 - Enter the Workspace container:
```bash ```bash
docker exec -it {workspace-container-name} bash docker-compose exec workspace bash
``` ```
Add `--user=laradock` (example `docker-compose exec --user=laradock workspace bash`) to have files created as your host's user.
4 - Run anything you want :) 4 - Run anything you want :)
```bash ```bash
@ -532,19 +553,19 @@ phpunit
docker-compose up -d redis 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. 2 - Open your Laravel's `.env` file and set the `REDIS_HOST` to `redis`
```env ```env
REDIS_HOST=xxx.xxx.xxx.xxx REDIS_HOST=redis
``` ```
If you don't find the `REDIS_HOST` variable in your `.env` file. Go to the database config file `config/database.php` and replace the default `127.0.0.1` IP with your `Docker-IP` for Redis like this: If you don't find the `REDIS_HOST` variable in your `.env` file. Go to the database config file `config/database.php` and replace the default `127.0.0.1` IP with `redis` for Redis like this:
```php ```php
'redis' => [ 'redis' => [
'cluster' => false, 'cluster' => false,
'default' => [ 'default' => [
'host' => 'xxx.xxx.xxx.xxx', 'host' => 'redis',
'port' => 6379, 'port' => 6379,
'database' => 0, 'database' => 0,
], ],
@ -642,7 +663,7 @@ docker-compose up -d mongo
5 - Open your Laravel's `.env` file and update the following variables: 5 - Open your Laravel's `.env` file and update the following variables:
- set the `DB_HOST` to your `Docker-IP`. - set the `DB_HOST` to your `mongo`.
- set the `DB_PORT` to `27017`. - set the `DB_PORT` to `27017`.
- set the `DB_DATABASE` to `database`. - set the `DB_DATABASE` to `database`.
@ -657,7 +678,7 @@ More details about this [here](https://github.com/jenssegers/laravel-mongodb#ins
7 - Test it: 7 - Test it:
- First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent). - First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent).
- Enter the Workspace Container `docker exec -it laradock_workspace_1 bash`. - Enter the Workspace Container.
- Migrate the Database `php artisan migrate`. - Migrate the Database `php artisan migrate`.
@ -805,92 +826,19 @@ It should be like this:
### [Misc] ### [Misc]
<a name="Run-Docker-Virtual-Host"></a>
### Run a Docker Virtual Host
These steps are only for **Windows & MAC** users *(Linux users don't need a virtual host)*:
1 - Run the default Host:
```bash
docker-machine start default
```
* If the host "default" does not exist, create one using the command below, else skip it:
* ```bash
docker-machine create -d virtualbox default
```
2 - Run this command to configure your shell:
```bash
eval $(docker-machine env)
```
<br>
<a name="Find-Docker-IP-Address"></a>
### Find your Docker IP Address
**On Windows & MAC:**
Run this command in your terminal:
```bash
docker-machine ip default
```
If your Host name is different then `default`, you have to specify it (`docker-machine ip my-host`).
*(The default IP is 192.168.99.100)*
<br>
> **boot2docker** users: run `boot2docker ip` *(when boot2docker is up)*.
<br>
**On Linux:**
Run this command in your terminal:
```shell
ifconfig docker0 | grep 'inet' | cut -d: -f2 | awk '{ print $1}' | head -n1
```
*(The default IP is 172.17.0.1)*
<br> <br>
<a name="Use-custom-Domain"></a> <a name="Use-custom-Domain"></a>
### Use custom Domain (instead of the Docker IP) ### Use custom Domain (instead of the Docker IP)
Assuming your custom domain is `laravel.dev` and your current `Docker-IP` is `xxx.xxx.xxx.xxx`. Assuming your custom domain is `laravel.dev`
1 - Open your `/etc/hosts` file and map your `Docker IP` to the `laravel.dev` domain, by adding the following: 1 - Open your `/etc/hosts` file and map your localhost address `127.0.0.1` to the `laravel.dev` domain, by adding the following:
```bash ```bash
xxx.xxx.xxx.xxx laravel.dev 127.0.0.1 laravel.dev
``` ```
2 - Open your Laravel's `.env` file and replace the `127.0.0.1` default values with your `{Docker-IP}`. 2 - Open your browser and visit `{http://laravel.dev}`
<br>
Example:
```env
DB_HOST=xxx.xxx.xxx.xxx
```
3 - Open your browser and visit `{http://laravel.dev}`
Optionally you can define the server name in the nginx config file, like this: Optionally you can define the server name in the nginx config file, like this:
@ -972,6 +920,8 @@ It should be like this:
3 - Re-build the container `docker-compose build workspace` 3 - Re-build the container `docker-compose build workspace`
<br> <br>
<a name="debugging"></a> <a name="debugging"></a>
### Debugging ### Debugging
@ -995,6 +945,29 @@ Use `http://127.0.0.1` (or [your Docker IP](#Find-Docker-IP-Address)) instead of
Make sure the ports for the services that you are trying to run (80, 3306, etc.) are not being used already by other programs, such as a built in `apache`/`httpd` service or other development tools you have installed. Make sure the ports for the services that you are trying to run (80, 3306, etc.) are not being used already by other programs, such as a built in `apache`/`httpd` service or other development tools you have installed.
<br>
<a name="upgrading"></a>
### Upgrading Docker
#### From Docker Toolbox (VirtualBox) to Docker for Mac/Windows (Native)
1. Stop the docker vm `docker-machine stop {default}`
2. Install Docker for [Mac](https://docs.docker.com/docker-for-mac/) or [Windows](https://docs.docker.com/docker-for-windows/).
3. Upgrade LaraDock to `v4.*.*`.
4. Use LaraDock as you used to do: `docker-compose up -d nginx mysql`.
**Note:** If you face any problem with the last step above: rebuild all your containers "Warnning Containers Data might be lost!"
`docker-compose build --no-cache`
<br> <br>
## Contributing ## Contributing

17
apache2/Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM webdevops/apache:ubuntu-16.04
MAINTAINER Eric Pfeiffer <computerfr33k@users.noreply.github.com>
ARG PHP_SOCKET="php-fpm:9000"
ENV WEB_PHP_SOCKET=$PHP_SOCKET
ENV WEB_DOCUMENT_ROOT=/var/www/laravel/public
EXPOSE 80 443
WORKDIR /var/www/laravel/public
ENTRYPOINT ["/opt/docker/bin/entrypoint.sh"]
CMD ["supervisord"]

View File

@ -7,9 +7,9 @@ RUN apt-get update && apt-get install -y curl
RUN curl -sL https://github.com/ptrofimov/beanstalk_console/archive/master.tar.gz | tar xvz -C /tmp RUN curl -sL https://github.com/ptrofimov/beanstalk_console/archive/master.tar.gz | tar xvz -C /tmp
RUN mv /tmp/beanstalk_console-master /source RUN mv /tmp/beanstalk_console-master /source
RUN apt-get remove --purge -y curl && RUN apt-get remove --purge -y curl && \
apt-get autoclean && apt-get autoclean && \
apt-get clean && apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 2080 EXPOSE 2080

View File

@ -12,6 +12,8 @@ services:
- INSTALL_XDEBUG=false - INSTALL_XDEBUG=false
- INSTALL_NODE=false - INSTALL_NODE=false
- COMPOSER_GLOBAL_INSTALL=false - COMPOSER_GLOBAL_INSTALL=false
- PUID=1000
- PGID=1000
volumes_from: volumes_from:
- volumes_source - volumes_source
tty: true tty: true
@ -49,6 +51,23 @@ services:
links: links:
- php-fpm - php-fpm
### Apache Server Container ##################################
apache2:
build:
context: ./apache2
args:
- PHP_SOCKET="php-fpm:9000"
volumes_from:
- volumes_source
volumes:
- ./logs/apache2:/var/log/apache2
ports:
- "80:80"
- "443:443"
links:
- php-fpm
### HHVM Container ########################################## ### HHVM Container ##########################################
hhvm: hhvm:
@ -188,12 +207,12 @@ services:
volumes_data: volumes_data:
build: ./volumes/data build: ./volumes/data
volumes: volumes:
- /var/lib/mysql:/var/lib/mysql - ./data/mysql:/var/lib/mysql
- /var/lib/postgres:/var/lib/postgres - ./data/postgres:/var/lib/postgres
- /var/lib/mariadb:/var/lib/mariadb - ./data/mariadb:/var/lib/mariadb
- /var/lib/memcached:/var/lib/memcached - ./data/memcached:/var/lib/memcached
- /var/lib/redis:/data - ./data/redis:/data
- /var/lib/neo4j:/var/lib/neo4j/data - ./data/neo4j:/var/lib/neo4j/data
- /var/lib/mongo:/data/db - ./data/mongo:/data/db
### Add more Containers below ############################### ### Add more Containers below ###############################

View File

@ -60,12 +60,25 @@ RUN if [ ${INSTALL_MONGO} = true ]; then \
echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini \ echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini \
;fi ;fi
#####################################
# Non-Root User:
#####################################
# Add a non-root user to prevent files being created with root permissions on host machine.
ARG PUID=1000
ARG PGID=1000
RUN groupadd -g $PGID laradock && \
useradd -u $PUID -g laradock -m laradock
# Now switch to our laradock user for the rest of user setup
USER laradock
##################################### #####################################
# Composer: # Composer:
##################################### #####################################
# Add the composer.json # Add the composer.json
ADD ./composer.json /root/.composer/composer.json ADD ./composer.json /home/laradock/.composer/composer.json
# Check if global install need to be runned # Check if global install need to be runned
ARG COMPOSER_GLOBAL_INSTALL=true ARG COMPOSER_GLOBAL_INSTALL=true
@ -84,13 +97,13 @@ ARG INSTALL_NODE=true
ENV INSTALL_NODE ${INSTALL_NODE} ENV INSTALL_NODE ${INSTALL_NODE}
RUN if [ ${INSTALL_NODE} = true ]; then \ RUN if [ ${INSTALL_NODE} = true ]; then \
# Install nvm (A Node Version Manager) # Install nvm (A Node Version Manager)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash \ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash \
;fi ;fi
# Again check if NVM needs to be installed # Again check if NVM needs to be installed
# I had to split this condifiton link this because when I get it inside the above if statment is refuses to work! # I had to split this condition link this because when I get it inside the above if statement is refuses to work!
ENV if [ ${INSTALL_NODE} = true ]; then \ ENV if [ ${INSTALL_NODE} = true ]; then \
# Set the ENV # Set the ENV
NVM_DIR=/root/.nvm \ NVM_DIR=/home/laradock/.nvm \
# Install NodeJS with NVM # Install NodeJS with NVM
RUN . ~/.nvm/nvm.sh && \ RUN . ~/.nvm/nvm.sh && \
nvm install stable && \ nvm install stable && \
@ -99,6 +112,14 @@ ENV if [ ${INSTALL_NODE} = true ]; then \
npm install -g gulp bower \ npm install -g gulp bower \
;fi ;fi
# Wouldn't execute when added to the RUN statement in the above block
# Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
RUN if [ ${INSTALL_NODE} = true ]; then \
echo "" >> ~/.bashrc && \
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
;fi
# #
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Final Touch # Final Touch
@ -106,6 +127,7 @@ ENV if [ ${INSTALL_NODE} = true ]; then \
# #
# Clean up # Clean up
USER root
RUN apt-get clean && \ RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*