A pretty simplified Docker Compose workflow that sets up a LEMP (Linux, NGINX, MySQL, PHP) network of containers for local Laravel development.
Ports used in the project:
Software | Port |
---|---|
nginx | 8080 |
phpmyadmin | 8081 |
mysql | 3306 |
php | 9000 |
xdebug | 9001 |
redis | 6379 |
To get started, make sure you have Docker installed on your system and Docker Compose, and then clone this repository.
-
Clone this project:
git clone https://github.com/supermavster/docker-laravel-8.git
-
Inside the folder
docker-laravel-8
and Generate your own.env
to docker compose with the next command:cp .env.example .env
-
You need Create or Put your laravel project in the folder source; to create follow the next instructions Here.
-
Build the project whit the next commands:
docker-compose up --build
The configuration of the database must be the same on both sides .
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_ROOT_PASSWORD=secret
# source/.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
The only change is the DB_HOST
in the source/.env
where is called to the container of mysql
:
# source/.env
DB_HOST=mysql
To Down and remove the volumes we use the next command:
docker-compose down -v
Update Composer:
docker-compose run --rm composer update
Run compiler (Webpack.mix.js) or Show the view compiler in node:
docker-compose run --rm npm run dev
Run all migrations:
docker-compose run --rm artisan migrate
Add your Laravel project here (or create a new blank one).
Note: IF exist problems generate the project delete this README.md
The configuration of the database must be the same on both sides .
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_ROOT_PASSWORD=secret
# source/.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
The only change is the DB_HOST
in the source/.env
where is called to the container of mysql
:
# source/.env
DB_HOST=mysql
A little help to create the project:
docker-compose run --rm composer create-project laravel/laravel .
cp .env.example .env
docker compose run --rm composer install
docker compose run --rm npm install
docker compose run --rm artisan clear:data
docker compose run --rm artisan cache:clear
docker compose run --rm artisan view:clear
docker compose run --rm artisan route:clear
docker compose run --rm artisan clear-compiled
docker compose run --rm artisan config:cache
docker compose run --rm artisan storage:link
docker compose run --rm artisan key:generate
docker compose run --rm artisan migrate --seed
docker compose run --rm artisan october:migrate
docker compose run --rm artisan passport:install