Package Data | |
---|---|
Maintainer Username: | hackley2 |
Maintainer Contact: | andrew@andrewhackley.com (Andrew Hackley) |
Package Create Date: | 2017-03-31 |
Package Last Update: | 2018-01-19 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-04-28 15:02:40 |
Package Statistics | |
---|---|
Total Downloads: | 49 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This Laravel Package helps get you up and running with a docker development environment in no time. No need to bog your host computer down with installing a LAMP stack directly.
Installing Laravel required PHP and Composer installed. If you're following Docker best practices, then you'll want to do the following instead of running https://laravel.com/docs/installation directly on your host machine (because you may not have PHP installed on your host computer).
NOTES: The following commands assume you already have docker CE installed https://docs.docker.com/engine/installation and that your host computer is running Linux or macOS. If you're running Windows, you will need to modify the following commands or be using Microsoft's Bash on Windows https://msdn.microsoft.com/en-us/commandline/wsl/install_guide .
# Run from host machine to access a php terminal
docker run -ti --rm -u $(id -u):$(id -g) -v $PWD:/var/www/html hackley2/php-apache bash
composer create-project --prefer-dist laravel/laravel blog
cd blog
Now that you have your Laravel Project set up, and your terminal is still running the composer bash prompt we opened up in step 2 we can set up the Docker files required for our development environment
composer require hackley2/laravel-docker-package
// PHP code to enter in config/app.php
Hackley2\LaravelDockerPackage\DockerServiceProvider::class,
php artisan vendor:publish --tag=docker
exit
Now that the docker files are all in place, follow these steps to spin up and manage your Docker LAMP stack:
# Start your docker server containers
docker-compose up -d
# Stop your docker server containers
docker-compose stop
docker ps
to determine the name of your "phpserver"
container and then use the ./docker-exec.sh
script file (see below for more details).
If you need to run a command in one of your docker containers (such as getting access to your docker container's terminal) use the following command:
# Run command on one docker container (from MacOS host machine)
docker exec -ti <docker-container-name> <command>
# Run command on one docker container (from Linux host machine)
docker exec -ti -u $(id -u):$(id -g) <docker-container-name> <command>
If you find that command to be too cumbersome, you can instead use the docker-exec.sh
script as follows:
./docker-exec.sh <container-name> <command>
To connect to your mysql server, use this command in your terminal, or enter this commands credentials into your favorite database management program. Use the database password set in your .env file.
# Replace <DB_USERNAME> with the value defined in your .env file
# Use the password defined in your .env file
mysql -u <DB_USERNAME> -p -h 127.0.0.1 -P 33061
If you need to run redis, memcached, node.js, or some other server environment, add a new service to the docker-compose.yml file in your project's root. If you don't know enough about Docker to do this, then I'd highly recommend the Docker For Developers book by Chris Tankersley. It's not expensive and provides a great introduction to Docker. It's available via eBook and soft cover at https://www.phparch.com/books/docker-for-developers/ .
If you need PHP extensions that aren't available in hackely2/php-apache, create your own docker file that has the extensions you need. You can even build upon hackley2/php-apache and extend it instead of starting from scratch.