This is a Dockerized Laravel Application built using the following containers:
-
PHP Application
PHP8.0-fpm, Composer, NPM, Node.js v14.x
-
MySQL
-
Nginx
- Docker Engine (v19.03.0+)
- Docker Compose
You can either:
- Install Docker Desktop (includes both Docker Engine and Docker Compose)
OR
- Install Docker Engine and Docker Compose separately.
-
Open a new instance of the terminal, navigate to the root directory of the project and execute the following command to bring all the containers up.
$ docker-compose up -d
The command will take a while to run, since it will download/build the images for the first time. After the images are ready, it will start the containers. The next time you run this command it will be way faster to execute.
note: any change you make to the Dockerfile or any other file that the Dockerfile uses (excluding docker-compose.yaml) you will need to build the images again for the changes to take effect by executing the following command.
$ docker-compose build && docker-compose up -d
-
When all containers are up and running, enter the app container by executing the following command.
$ docker-compose exec blog_app bash
-
Install all composer packages included in composer.json
$ composer install
-
Install all npm packages included in package.json
$ npm install
-
Run all mix tasks.
$ npm run dev
-
Create a .env file from the existing .env.example
$ cp .env.example .env
-
Generate a Laravel App Key.
$ php artisan key:generate
-
Run the database migrations.
$ php artisan migrate
-
Modify the following fields in your .env file to use the values specified in the database container.
DB_CONNECTION=mysql DB_HOST=blog_db DB_PORT=3306 DB_DATABASE=blog DB_USERNAME=root DB_PASSWORD=root
-
To access your Laravel Application visit http://localhost:8000
If you intend to modify the assets (JS/CSS) make sure to run
$ npm run watch
This command will continue to run in your terminal and watch relevant files for changes.
To run the tests you should be inside the application container.
-
Enter the application container
$ docker-compose exec blog_app bash
-
Run the tests
$ vendor/bin/phpunit
-
Exit the app container.
$ exit
-
Bring all the containers down.
$ docker-compose down