Laravel with Docker in just 5 minutes2 min read
In this guide I will teach you how to setup Laravel with Docker project for a dev environment. After you finish with this article you will have Laravel running in Docker, without the need to understand Docker as I have prebuild it for you.
Before you are moving on with the guide, you should have installed Docker. The setup works indifferently on MacOS and Windows and should also work on Linux. You can download Docker here: https://www.docker.com/products/docker-desktop
Make a new project as per according to Laravel documentation:
composer new MyProject
Download my script to your project folder (feel free to open the URL and investigate it):
curl https://raw.githubusercontent.com/EmilMoe/vm/master/vm --output vm
On MacOS and Linux you might have to make the file executable:
chmod +x vm
Configure Laravel settings
Before you build your project, you must change a few things in your
.env. If you change this after you build the environment, the setup won’t work.
.env in Sublime Text or any other text editor and change these variables:
# Set App name, the Docker container will use this name APP_NAME=YOUR_APP # Database should be configured to the Docker environment. Database name is optionally but I like to name it after my project DB_CONNECTION=mysql DB_HOST=database DB_PORT=3306 DB_DATABASE=YOUR_APP DB_USERNAME=root DB_PASSWORD=secret
You are now ready to build your environment:
Y to begin the process.
After it’s done, you can browse to
http://localhost to verify that Laravel works.
Using the script
Your Docker instance is already up and running, to stop it again simply run
And to start it
There are a few more commands such as
npm but that would executive them inside the container where they should generally be run outside on your host machine.
To get a list of available commands use: