In this short lesson we’re gonna focus on two topics we tackled some time ago in this mini series of tutorials: Laravel and Docker.
In the getting started section of the Laravel project’s documentation we can see that a vagrant box named Homestead is strongly adviced to begin with a quick and smooth developing experience.
Homestead is pre-packed with all the stuff necessary to begin the development of a Laravel application, but when it comes to deploying any application, Docker has many strong points that other virtual environments have not. In many cases it is a must: see this article of mine for further details.
In this tutorial then, we’re going to put together two concepts we saw in our previous lessons, please refer to this other blog post of this series along with the one on Docker linked above: the episode about Laravel.
It may also be useful to look at our Ruby on Rails tutorial to get a general picture, that one is also based on Docker.
The first thing to do is to create our Laravel stack, it will be based on the bitnami Laravel docker containers, go to your shell and type the following commands:
$ mkdir laravel_tutorial && cd laravel_tutorial $ curl -LO https://raw.githubusercontent.com/bitnami/bitnami-docker-laravel/master/docker-compose.yml $ docker-compose up
Your Laravel default application should be up and running after a few time for downloading all the images from the repos. All you have to do now is to point your browser at this location: http://0.0.0.0:3000 and you should see the default Laravel welcome page.
The next thing you should do is to open another terminal within your shell and issue the following command, you will enter your container’s shell:
$ docker exec -it laravel_tutorial_myapp_1 /bin/bash
Now all you have to do is to follow the instructions from this previous tutorial of mine, the only difference is that all the shell commands will be issued inside the container’s shell, and the final command to start the artisan server will not be necessary, in that artisan will be already running: so here you can continue the lesson.
And that’s all for now, in this quick lesson we looked at a very simple Laravel application running on Docker. We saw two development environments, Homestead and Docker, and we quickly discussed them.
This tutorial is based on Fedora 29, you might encounter some little difficulties running the same application on other operating systems such as Ubuntu, but with a little bit of patience you can surely overcome them.
Should you have any question, I welcome you to contact me in person and I’ll be answering as soon as possible.
If you need a reference for the inherent code, the repo is the same of the preceding Laravel tutorial: go to my GitHub. In addition to that repo you will also find a ‘docker-compose.yml‘ file inside your app’s root directory.
Did you like this post? Please comment here below and share it on your preferred social networks, thank you!
Hi there. My name is Mirko Benedetti, I’m a Software Developer and I founded Benedict Engineers. Excellence is what I consider to be our ultimate goal, and passion for technology constantly drives me to it. I began programming self-taught at a very young age. Since then I learned a lot, and every day I enjoy learning new things. Here is my Linkedin Curriculum, feel free to connect.