Provides Docker and Elastic Beanstalk integration for a Laravel 5 project
by Reflexions, (*1)
chmod 777
1.) Install Docker Toolbox to get docker, docker-compose, and the Kitematic GUI. Open a terminal with the docker env variables via Kitematic -> File -> Open Docker Command Line Terminal
, (*2)
2.) Create a docker-compose.yml in the project directory. Define the laravel service and any desired database services:, (*3)
laravel: image: reflexions/docker-laravel:latest ports: - 80:80 env_file: .env links: - database volumes: - .:/var/www/laravel database: image: postgres:9.6 ports: - 5432:5432 env_file: .env environment: LC_ALL: C.UTF-8
3.) Obtain a Github Personal Access Token. Create an .env file in the project directory. Configure laravel and other services as desired. The database
service above corresponds to DB_HOST=database
below:, (*4)
# laravel service GITHUB_TOKEN=Your_Github_Token APP_KEY=SomeRandomString DB_CONNECTION=pgsql DB_HOST=database DB_DATABASE=application DB_USERNAME=username DB_PASSWORD=password # database service POSTGRES_DB=application POSTGRES_USER=username POSTGRES_PASSWORD=password
4.) With one command download the images, create the service containers, and start the application:, (*5)
docker-compose up
5.) (optional) APP_KEY, (*6)
$ docker exec -it $(docker ps | grep reflexions/docker-laravel | awk '{print $1}') bash root@4c0491540409:/var/www/laravel# php artisan key:generate
6.) (optional) Tinker, (*7)
$ docker exec -it $(docker ps | grep reflexions/docker-laravel | awk '{print $1}') bash root@4c0491540409:/var/www/laravel# php artisan tinker
reflexions/docker-laravel
composer packageReflexions\DockerLaravel\DockerApplication
to prevent permissions errorsFront-end build systems (gulp, grunt, bower, etc) are best installed outside of docker. The resulting assets will be readily accessible via the volume mapping defined on the laravel service., (*8)
Add a Dockerfile to the root of the project to deploy with Elastic Beanstalk:, (*9)
FROM reflexions/docker-laravel:latest MAINTAINER "Your Name" <your@email.com> COPY . /var/www/laravel WORKDIR /var/www/laravel EXPOSE 80 ENTRYPOINT ["/usr/share/docker-laravel/bin/start.sh"]
This will define an application container. Use RDS to create the database. Add all variables from the .env file (including the APP_KEY, DB_HOST, etc) into the AWS Management Console
-> Elastic Beanstalk
-> Your-Environment
-> Configuration
-> Software Configuration
., (*10)
$ docker-compose up ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`. $
Solution: Open terminal with Kitematic -> File -> Open Docker Command Line Terminal
., (*11)
Solution: Run Kitematic -> Install Docker Commands
. Then add the following line ~/.bash_profile:, (*12)
eval "$(docker-machine env dev)"
Solution: Restart cluster. Settings in the .env file are only read on start., (*13)
$ docker-compose restart
$ docker-compose up Illegal instruction: 4 $
Solution: Known issue with the Docker Toolbox on older CPUs. Install docker-compose using pip, (*14)
Solution: - Check that the DB_CONNECTION corresponds to the correct laravel db driver - Check that the DB_HOST corresponds to the name of the service listed in docker-compose.yml (i.e. "database" in the example above), (*15)
Solution:, (*16)
php artisan key:generate
to update APP_KEY on .env, then restart the container.Solution:
- Modify docker-config.yml
to reference MySQL:, (*17)
laravel: image: reflexions/docker-laravel:latest ports: - 80:80 env_file: .env links: - database volumes: - .:/var/www/laravel database: image: mysql:5.6 ports: - 3306:3306 env_file: .env environment: LC_ALL: C.UTF-8
.env
to reference MySQL:# laravel service GITHUB_TOKEN=Your_Github_Token APP_KEY=SomeRandomString DB_CONNECTION=mysql DB_HOST=database DB_DATABASE=application DB_USERNAME=username DB_PASSWORD=password # database service MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=application MYSQL_USER=username MYSQL_PASSWORD=password
Solution:
- Modify docker-config.yml
to drop the unnecessary database service:, (*18)
laravel: image: reflexions/docker-laravel:latest ports: - 80:80 env_file: .env volumes: - .:/var/www/laravel
.env
to connect to MySQL via the docker-machine host ip address (192.168.99.1):# laravel service GITHUB_TOKEN=Your_Github_Token APP_KEY=SomeRandomString DB_CONNECTION=mysql DB_HOST=192.168.99.1 DB_DATABASE=application DB_USERNAME=username DB_PASSWORD=password
my.cnf
, or it can be hard coded in your startup script. To check the value use this sql:show variables like 'bind_address';
CREATE USER 'username'@'192.168.99.100' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON application.* TO 'username'@'192.168.99.100'; FLUSH PRIVILEGES;