Skip to content

sschonss/tutorial-docker-laravel-mariadb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Docker & Laravel

Laravel + MariaDB


Introduction 📄

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.


Installation 🐳

Docker

For Windows, you need to install WSL2 and Docker Desktop

Docker Compose


Usage 🚀

Clone the docker-compose.yml file

mkdir ~/myapp && cd ~/myapp
curl -LO https://raw.githubusercontent.com/bitnami/containers/main/bitnami/laravel/docker-compose.yml

Attention ⚠️

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.

Start the services 💪

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.

Stop the services 🛑

docker-compose down

Tips 💡

Check the status of the containers

docker-compose ps

Check the logs of the containers

docker-compose logs

Check the logs of a specific container

docker-compose logs <container-name>

Check the logs of a specific container in real time

docker-compose logs -f <container-name>

Access the application 💻

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.

Access the database 💾

I recommend you use DBeaver or DataGrip to access the database.

You can use the credentials defined in the docker-compose.yml file.

Access the container 📦

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.

Final considerations 📝

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. 😄

LinkedIn GitHub


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published