nguonchhay/dockerlaravel

Dockerlaravel is for enhance local development

5.6.0 2018-09-05 04:34 UTC

This package is not auto-updated.

Last update: 2020-07-30 11:07:50 UTC


README

DockerLaravel creates the necessary Docker containers (webserver, database, php, mail, redis, couchdb) to run your Laravel Framework project. The package provides a wrapper script in vendor/bin/dockerlaravel which simplifies the handling of docker and does all the configuration necessary.

We created this package to make development on Laravel Framework projects easier and to create a simple reusable package which can easily be maintained and serves well for the standard project.

Features for this docker image

  • PHP: 7.1
  • Nginx: 1.7
  • Mariadb: 10.3
  • Mailhog: latest
  • Redis: 3.0
  • Couchdb: 1.6

Install docker

https://docs.docker.com/installation/ (tested with docker v1.9 - v1.12)

Install docker-compose

We use docker-compose to do all the automatic configuration:

http://docs.docker.com/compose/install/ (tested with docker-compose v1.5 - v1.6)

The repository contains a Dockerfile which will automatically be built in the docker hub after each change and used by docker-compose to build the necessary containers.

On a Mac or Windows

It has been tested working with docker for Mac but not yet with docker for Windows. Feel free to try out and let us know if you cannot wait.

Install dockerlaravel into your distribution

Add nguonchhay/dockerlaravel as dev dependency in your composer.

composer require --dev nguonchhay/dockerlaravel 5.6.*

Point db to your host

0.0.0.0 db

NOTE: this step require when you are using docker for the first time. You can skip this step for next setup.

Starting the docker services

vendor/bin/dockerlaravel up -d

Point domain to your host

0.0.0.0 your-domain-name test.your-domain-name # port does not need here

After starting the docker services, you will get the domain name exactly the same as your root directory.

Example:

Root directory is `laravel` then your domain name is `laravel:8080`

- Open your website

	http://laravel:8080
	
- Open your test website

	http://test.laravel:8080

Check the status

vendor/bin/dockerlaravel ps

Configure .env for running in local environment

APP_ENV=local
APP_KEY=your-generated-key
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=your-local-domain

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=dockerlaravel
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=0.0.0.0
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

Starting app service

vendor/bin/dockerlaravel run app /bin/bash

app container is the place where you run your commands that have connection to database.

Starting db service

vendor/bin/dockerlaravel run db /bin/bash

db container is the place where you can check your MySQL database information. The default two databases were created: dockerlaravel and dockerlaravel_test

NOTE: Services can currently be app, web, data, db, redis, or couchdb.

Accessing to CouchDB

From your host machine, you can access couchdb from web interface or command line:

Web: http://hostname-couchdb:5984/_utils/ -> replace hostname with project name

Cli: curl -X GET http://hostname-couchdb:5984/_all_dbs

From inside your app container, you can also access couchdb through the command line:

vendor/bin/dockerlaravel run app /bin/bash
curl -X GET http://couchdb:5984/_all_dbs

Attach to a running service

Run vendor/bin/dockerlaravel ps and copy the container's name that you want to attach to.

Run docker exec -it <containername> /bin/bash with the name you just copied. With this you can work in a running container instead of creating a new one.

Check open ports in a container

vendor/bin/dockerlaravel run SERVICE netstat --listen

Credit to Sebastian Helzle