A complete Laravel development environment in Docker Containers:
- Bring Up a Laravel development environment with a single command easy as
dup - Execute Artisan commands easy as
dartisan make:auth - Run Composer command easy as
dcomposer update - Run NodeJS script easy as
dnodejs npm install - Run gulp watch easy as
dgulp-watch - Containers managed with docker-compose
- Lightweight as it is mostly based in Linux Alpine base image of 5MB.
Containers included
- Nginx 1.8.0 & PHP 5.6 running in Alpine
- MariaDB 5.5 running in Alpine
- Redis running in Alpine
- Composer PHP running in Alpine.
- Artisan running in Debian (alpine is missing some PHP packages)
- NodeJS with gulp, grunt and bower -g installed in official node:4.2.2-slim base image
- Volumes mounted as containers
Usage
Make sure you havedocker and docker-compose installed. See here for installing them- clone this repo:
git clone https://github.com/SpiralOutDotEu/dockervel.git - cd in:
cd dockervel - run as su:
su - add aliases:
. ./aliases.sh - run:
dupand you have a server running! Hitlocalhostin your browser and you will see nginx fault message becasuse there is nowww/public/index.php. - create new Laravel project:
dcomposer-create - fix permissions:
dpermit - change .env: see below for options
- run artisan commands:
dartisan make:auth - fix permissions:
dpermitNow you have a registration system active. Go tolocalhostand register a new user to see that db's are running ok. - npm install:
dnodejs npm install - gulp install:
dnodejs gulp install - gulp watch:
dulp-watchNow there is one container runninggulp watchand monitors changes on files according yourgulpfile.js
aliases
aliases.sh contains shortcuts to common commands. run dot space dot /aliashes.sh to activate aliases for this terminal session.$ . ./aliases.sh
and now for this terminal session you have aliases like dartisan, dcomposer, dnodejs, dup, dstop. If you don't want to work with aliases, open the script and see the coressponding commands next to each alias. In the following document it is supposed that you have executed
aliashes.sh as su and you have the aliases active. Create new Laravel Project
- create new laravel project:
dcomposer-create - type
localhostin your browser and you see the Laravel welcome screen
Fix permitions
since containers have different user in them, you have to change the permisions in www/ folder to be able to write. type:$ dpermit
it will simply chmod -R 777 www
Remember to run dpermit after each time the www folder has a new file.Configure Laravel for mysql
changeDB_HOST in .env to point to mysql. This is the name that it is used in docker-compose.yml (link: -mysql:mysql)DB_HOST=mysql
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Configure Laravel for redis
changeREDIS_HOST in .env to point to predis. This is the name that it is used in docker-compose.yml (link: -redis:predis).REDIS_HOST=predis
REDIS_PASSWORD=null
REDIS_PORT=6379
in Laravel 5.2 there are some issues with redis namespace, so to avoid conflicts predis is used.
Also you have to change /config/app.php, and replace:'Redis' => Illuminate\Support\Facades\Redis::class,
with'LaravelRedis' => Illuminate\Support\Facades\Redis::class,
Use it like:$redis= LaravelRedis::connection();
$redis->set('name', 'myname');
$redis->get('name');
Running Artisan commands
typedartisan followed by an artisan commandexample:
$ dartisan make:auth
$ dartisan migrate
$ dartisan tinker
Running composer commands
typedcomposer followed by a composer commandexample:
$ dcomposer update
$ dcomposer require predis/predis
Nodejs
to install node modules in your project run$ dnodejs npm install
Gulp
install gulp with:dnodejs gulp install:
run gulp once:dgulp
add gulp watch:dgulp-watch
Size
The size of images is about 750 MB:* front: 70.05 MB
* mysql: 199.50 MB
* redis: 8.50 MB
* composer: 236.80 MB
* nodejs: 36.09 MB
* artisan 208.80 MB
The base memory usage for the containers of the server running is about 110 MB.* front: 18 MB
* mysql: 97 MB
* redis: 1 MB

Nice work Man, I was working on something similar over the weekend.
ReplyDeleteNice work Man, I was working on something similar over the weekend.
ReplyDeleteGlad i've helped. I'm working on adding PHP Unit right now, keep in touch.
DeleteGitHub
Twitter
I'd prefer to install the images via Docker Hub instead of using git clone. Would you make images there?
ReplyDeleteFrom GitHub you get only the docker-compose-yml(and asistant files). All images are pulled from Docker Hub.
DeleteHi there,
ReplyDeletethanks for the setup. Actually I started and tried to install the debug bar (which requires php-iconv), how do I add custom APK packages to the docker instance?
thank you
Simom
Hi Simom,
DeleteNice remark about debug bar. I've updated Dockervel so that it supports iconv. Update your local repository and you are ready. Try it out and let me now if it is ok.
You can add packages to the docker instace by adding them to the docker file.
See related commit here
Now change the docker-composer.yml to link to the new image. see related commit here.
Learn more about automated builds from github to dockerhub here
good job sir!
ReplyDeleteThank you m@ntrax!
DeleteOr you can try a much better solution like LaraDock https://github.com/LaraDock/laradock
ReplyDeleteI need help. I can't find the .env to make changes.
ReplyDeleteDB_HOST=mysql
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Or I have to make the env changes in the docker-compose.yml file
.env file is part of you laravel project. It is located at the root of your laravel project. As a "." file it is hidden by default in your file browser. Try to enable the "show hidden files" on your file browser.
DeleteI need some suggestion . Well I have to make a laravel app using Behat(software for BDD ). Is there any way I can use Behat in this environment?
ReplyDeleteI'm not familiar with Behat but i think that you can install it with `dcomposer require --dev behat/behat=~3.0.4` . A solution to run it from a container might be something like creating dartisan similar dockerfile, remove the entrypoint and use it like a php container. If you added in your docker-compose.yml for example you could call it like `docker-compose run dbehat behat --init`.
DeleteHope that i've helped
Can you help further on the above question? I happen to want to do the same thing. I installed behat with composer.
DeleteI added in the docker-compose.yml:
behat:
image: tvial/behat
volumes:
- ./www:/var/www
networks:
- back-tier
And I get
ERROR: for behat No command specified
I then tried to run:
docker-compose run www/vendor/behat/behat/bin/behat
(it's the path to behat) and got
ERROR: No such service: www/vendor/behat/behat/bin/behat
Any help appreciated
This comment has been removed by the author.
ReplyDeleteI have gone true the installation ,it's seemed ok. When I run dartisan serve and visit localhost ="The site can't be reached"
ReplyDeleteIn /var/www/ I have one laravel project that I used to load running also the localhost. What can I change to make this work? In hosts file I have for the use of previous laravel proj. endited this
127.0.0.1 laravel.example.com .
I'm sorry if the questions are dumb but I'm a newbie.
1) if you have another web server running, like WAMP, you should stop it because they are trying to use the same ip.
Delete2) dont forget to change the permitions to www with `dpermit`
Hope that one of both will do the work
Can like run something like this
ReplyDeletephp -S localhost:8888 -t public
in this container?
If you want to change the port, change it through `docker-compose.yml` and `port: 8888:80`.
DeleteI have this docker image pulled ,and worked something on the app ,made some changes and I want to send it to my friend like a docker image. But I'm not sure how to make a dockerfile ,using your dockervel as base .Can you advice me how to put it together?
ReplyDeletehmm.. First of all, dockervel is not a single image. It consists of sevelar images orchestrated together by docker-compose (see docker-compose.yml). And the reason for that is that you don't need all the parts every time (eg. you don't load nodejs when all you want is to work with artisan). Also you can change parts (eg. you can change MySQL with Postgres).
DeleteIf you want to share your project, the easy way is to share the entire dockervel folder (please omit the node_modules folder, you can recreate it with `dcomposer install`).
If you realy want to make it a single dockerfile (not so good idea) you should combine each dockerfile into a single one and you will end up with a huge and not flexible container.
You could also try a docker-in-docker, but maybe first read this
This comment has been removed by the author.
ReplyDeleteI read that Post and got it fine and informative. Please share more like that...Great Article it its really informative and innovative keep here:
ReplyDeleteweb design | laravel development
Thank you Abhijit!
DeleteNice work with your Blog
This comment has been removed by a blog administrator.
ReplyDeleteValuable post useful for everyone.Keep on sharing.
ReplyDeleteKubernetes Online Training
Nice blog. You have provided such a useful information in this blog. Thanks for sharing.
ReplyDeleteDocker and Kubernetes Training
Docker and Kubernetes Training in Hyderabad
Kubernetes Online Training
Docker Online Training
hi your article is very easy understand and impressive.
ReplyDeletePHP Training in Chennai | Certification | Online Training Course | Machine Learning Training in Chennai | Certification | Online Training Course | iOT Training in Chennai | Certification | Online Training Course | Blockchain Training in Chennai | Certification | Online Training Course | Open Stack Training in Chennai |
Certification | Online Training Course
I feel really happy to have seen your webpage.I am feeling grateful to read this.you gave a nice information for us.please updating more stuff content...keep up!!
ReplyDeleteData Science Training In Chennai
Data Science Online Training In Chennai
Data Science Training In Bangalore
Data Science Training In Hyderabad
Data Science Training In Coimbatore
Data Science Training
Data Science Online Training
Very informative post! I'm learning a lot from your articles. Keep us updated by sharing more such posts.
ReplyDeleteJava Training in Chennai
Java Training in Bangalore
Java Training in Hyderabad
Java Training
Java Training in Coimbatore
thank you for the information
ReplyDeleteangular js course in chennai
angular course in chennai
angular js online course in chennai
angular js course in bangalore
angular js course in hyderabad
angular js course in coimbatore
angular js course
angular js online course
IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.
ReplyDeleteIEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.
corporate training in chennai corporate training in chennai
corporate training companies in india corporate training companies in india
corporate training companies in chennai corporate training companies in chennai
I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai Project Centers in Chennai