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. Nevertheless 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.
Let’s create our Laravel stack.
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. You should see the default Laravel welcome page.
Enter the container shell.
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. Moreover the final command to start the artisan server will not be necessary. 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. I quickly discussed them.
We used Fedora 29 to make this tutorial. You might encounter some little difficulties running the same application on other operating systems such as Ubuntu. Nevertheless, with a little bit of patience you can surely overcome them.
Should you have any more 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. So, go to my GitHub. In addition to that repo you will also find a ‘docker-compose.yml‘ file inside your app’s root directory.