This tutorial will help you to create a Laravel project using Docker.
My goal is to help you to create a Laravel project using Docker in a simple way.
I decided to write this tutorial because I had some difficulties to create a Laravel project using Docker and I want to help you to avoid these difficulties.
Flowing a documentation is a good way to learn, but sometimes you need to read a tutorial to understand it better.
However, I learned a lot of writing this tutorial, so it is a win-win situation.
If you have any questions, you can contact me on LinkedIn or GitHub.
That is my first tutorial in English, sorry for any mistakes.
For Windows, you need to install WSL2 and Docker Desktop
mkdir ~/myapp && cd ~/myapp
curl -LO https://raw.githubusercontent.com/bitnami/containers/main/bitnami/laravel/docker-compose.yml
You need to change environment variables in the docker-compose.yml file to your own values.
Sometimes, you need to change the ports in the docker-compose.yml file to avoid conflicts with other services.
Maybe you need to open your project ~/myapp
in your IDE or text editor to edit your .env file.
Remember to change the DB_HOST variable in your .env file to the name of the service defined in the docker-compose.yml file.
It can be necessary to change permissions of the ~/myapp
directory, because the container will create files in this directory, and maybe you can't edit these files.
docker-compose up
One tip: You can use the -d flag to run the containers in the background:
docker-compose up -d
I recommend you don't use the -d flag when you start the containers for the first time, because you can see the logs of the containers and check if everything is working correctly.
docker-compose down
docker-compose ps
docker-compose logs
docker-compose logs <container-name>
docker-compose logs -f <container-name>
In your terminal, you can see the URL of your application.
Normally, the URL is http://localhost:8000 if you don't change the ports in the docker-compose.yml file.
I recommend you use DBeaver or DataGrip to access the database.
You can use the credentials defined in the docker-compose.yml file.
You can access the container using the following command:
docker-compose exec <container-name> bash
If you use Windows, you can open Docker Desktop and click in the container name to open a terminal.
I recommend you read the Bitnami Laravel documentation to learn more about this image.
You can use this Bitnami Laravel image in production, but you need to change the environment variables in the docker-compose.yml file to your own values.
I wrote this tutorial to help you, but I don't know everything about Docker and Laravel, I'm learning too.
I hope this tutorial helps you. 😄