Compare commits

...

7 Commits

Author SHA1 Message Date
5d84c6481f revers the dependancies between php and the db
to prevent running all the db engines when php is running
2016-05-07 05:29:48 +03:00
26229e150d Merge pull request #35 from benmag/master
link postgres service to php service
2016-05-07 05:14:01 +03:00
2b98b0b82e update the readme, include supported containers 2016-05-07 05:10:57 +03:00
457c5d4b1b update the readme file
Support selecting your own containers in the docker compose command.
2016-05-07 05:03:07 +03:00
cd97ac0aa6 link postgres service to php service 2016-05-07 11:55:00 +10:00
22f11e03ee Merge pull request #34 from benmag/master
Add support for postgres
2016-05-07 04:34:27 +03:00
5d62ec1e67 Add support for postgres 2016-05-07 11:16:06 +10:00
3 changed files with 85 additions and 30 deletions

View File

@ -15,7 +15,7 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
- [Intro](#Intro) - [Intro](#Intro)
- [Default Containers](#Default-Containers) - [Supported Containers](#Supported-Containers)
- [Requirements](#Requirements) - [Requirements](#Requirements)
- [Installation](#Installation) - [Installation](#Installation)
- [Usage](#Usage) - [Usage](#Usage)
@ -24,7 +24,7 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
- [Close all running Containers](#Close-all-running-Containers) - [Close all running Containers](#Close-all-running-Containers)
- [Delete all existing Containers](#Delete-all-existing-Containers) - [Delete all existing Containers](#Delete-all-existing-Containers)
- [Build/Re-build Containers](#Build-Re-build-Containers) - [Build/Re-build Containers](#Build-Re-build-Containers)
- [Use Redis in Laravel](#Use-Redis-in-Laravel) - [Use Redis](#Use-Redis)
- [Use custom Domain](Use-custom-Domain) - [Use custom Domain](Use-custom-Domain)
- [Change the PHP Version](#Change-the-PHP-Version) - [Change the PHP Version](#Change-the-PHP-Version)
- [Add/Remove a Docker Container](#AddRemove-a-Docker-Container) - [Add/Remove a Docker Container](#AddRemove-a-Docker-Container)
@ -62,16 +62,16 @@ Seriously!!!
Instead of providing a full Virtual Machines, like you get with Vagrant, Docker provides you **lightweight** Virtual Containers, that share the same kernel and allow to safely execute independent processes. Instead of providing a full Virtual Machines, like you get with Vagrant, Docker provides you **lightweight** Virtual Containers, that share the same kernel and allow to safely execute independent processes.
<a name="Default-Containers"></a> <a name="Supported-Containers"></a>
## Default Containers ## Supported Containers
- PHP - PHP
- NGINX - NGINX
- MySQL - MySQL
- PostgreSQL
- Redis - Redis
- Data Volume - Data Volume
<a name="Requirements"></a> <a name="Requirements"></a>
## Requirements ## Requirements
- Laravel ([Download](https://laravel.com/docs/master/installation)) - Laravel ([Download](https://laravel.com/docs/master/installation))
@ -114,23 +114,36 @@ DB_HOST=xxx.xxx.xxx.xxx
[How to find my Docker IP Address?](#Find-Docker-IP-Address) [How to find my Docker IP Address?](#Find-Docker-IP-Address)
<br> <br>
2 - Run the containers: 2 - Run the Containers, (you can select the software's (containers) that you wish to run)
<br> <br>
*(Make sure you are in the `docker` folder before running this command)* *Make sure you are in the `docker` folder before running the `docker-compose` command.*
> Running PHP, NGINX and MySQL:
```bash ```bash
docker-compose up -d docker-compose up -d php nginx mysql
``` ```
>*Only the first time you run this command, it will take up to 5 minutes (depend on your connection speed) to download the Docker Images on your local machine.* Note: you can choose your own combination of software's (containers), another example:
> Running PHP, NGINX, Postgres and Redis:
```bash
docker-compose up -d php nginx postgres redis
```
Supported Containers: `php`, `nginx`, `mysql`, `postgres`, `redis`, `data`.
<br> <br>
3 - Open your browser and visit your `{Docker-IP}` address (`http://xxx.xxx.xxx.xxx`). 3 - Open your browser and visit your `{Docker-IP}` address (`http://xxx.xxx.xxx.xxx`).
> **Debugging**: in case you faced an error here, run this command from the Laravel root directory: <br>
> <br> **Debugging**: in case you faced an error here, run this command from the Laravel root directory:
> `sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache`
```bash
sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache
```
<br> <br>
@ -157,6 +170,12 @@ docker ps
docker-compose stop docker-compose stop
``` ```
To stop single container do:
```php
docker-compose stop {container-name}
```
<br> <br>
<a name="Delete-all-existing-Containers"></a> <a name="Delete-all-existing-Containers"></a>
#### Delete all existing Containers #### Delete all existing Containers
@ -166,23 +185,32 @@ docker-compose rm -f
*Note: Careful with this command as it will delete your Data Volume Container as well. (if you want to keep your Database data than you should stop each container by itself as follow):* *Note: Careful with this command as it will delete your Data Volume Container as well. (if you want to keep your Database data than you should stop each container by itself as follow):*
`docker stop {container-name}`
<br> <br>
<a name="Build-Re-build-Containers"></a> <a name="Build-Re-build-Containers"></a>
#### Build/Re-build Containers #### Build/Re-build Containers
If you do any change to any `dockerfile` make sure you run this command, for the changes to take effect:
```bash ```bash
docker-compose build docker-compose build
``` ```
Optionally you can specify which container to rebuild (instead of rebuilding all the containers), example rebuilding `PHP`:
```bash
docker-compose build php
```
<br> <br>
<a name="Use-Redis-in-Laravel"></a> <a name="Use-Redis"></a>
#### Use Redis in Laravel #### Use Redis
Open your Laravel's `.env` file and set the `REDIS_HOST` to your `Docker-IP` instead of the default `127.0.0.1` IP. 1 - First make sure you run the Redis Container with the `docker-compose` command.
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.
```env ```env
REDIS_HOST=xxx.xxx.xxx.xxx REDIS_HOST=xxx.xxx.xxx.xxx
@ -201,26 +229,27 @@ If you don't find the `REDIS_HOST` variable in your `.env` file. Go to the datab
], ],
``` ```
To enable Redis Caching and/or for Sessions Management. Also from the `.env` file set `CACHE_DRIVER` and `SESSION_DRIVER` to `redis` instead of the default `file`. 3 - To enable Redis Caching and/or for Sessions Management. Also from the `.env` file set `CACHE_DRIVER` and `SESSION_DRIVER` to `redis` instead of the default `file`.
```env ```env
CACHE_DRIVER=redis CACHE_DRIVER=redis
SESSION_DRIVER=redis SESSION_DRIVER=redis
``` ```
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 first.
```bash ```bash
composer require predis/predis:^1.0 composer require predis/predis:^1.0
``` ```
You can manually test it with: 5 - You can manually test it from Laravel with this code:
```php ```php
\Cache::store('redis')->put('laradock', 'awesome', 10); \Cache::store('redis')->put('laradock', 'awesome', 10);
``` ```
<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)

View File

@ -25,8 +25,16 @@ services:
- ./logs/php/:/usr/local/var/log - ./logs/php/:/usr/local/var/log
expose: expose:
- "9000" - "9000"
links:
- mysql ### DATA Container ##########################################
data:
build: ./data
container_name: data
volumes:
- /var/lib/mysql
- /var/lib/postgresql/data
- /var/lib/redis
### MySQL Container ######################################### ### MySQL Container #########################################
@ -42,6 +50,24 @@ services:
MYSQL_USER: homestead MYSQL_USER: homestead
MYSQL_PASSWORD: secret MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root MYSQL_ROOT_PASSWORD: root
links:
- php
### PostgreSQL Container ####################################
postgres:
build: ./postgres
container_name: postgres
volumes_from:
- data
ports:
- "5432:5432"
environment:
POSTGRES_DB: homestead
POSTGRES_USER: homestead
POSTGRES_PASSWORD: secret
links:
- php
### Redis Container ######################################### ### Redis Container #########################################
@ -53,13 +79,4 @@ services:
ports: ports:
- "6379:6379" - "6379:6379"
### DATA Container ##########################################
data:
build: ./data
container_name: data
volumes:
- /var/lib/mysql
- /var/lib/redis
### Add more Containers below ############################### ### Add more Containers below ###############################

9
postgres/Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM postgres:latest
MAINTAINER Ben M <git@bmagg.com>
VOLUME /var/lib/postgresql/data
CMD ["postgres"]
EXPOSE 5432