by Reflexions
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.) Create a docker-compose.yml in the project directory. Define the laravel service and any desired database services:
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:
# 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:
docker-compose up
5.) (optional) APP_KEY
$ 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
$ 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.
Add a Dockerfile to the root of the project to deploy with Elastic Beanstalk:
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
.
$ 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
.
Solution: Run Kitematic -> Install Docker Commands
. Then add the following line _~/.bashprofile:
eval "$(docker-machine env dev)"
Solution: Restart cluster. Settings in the .env file are only read on start.
$ docker-compose restart
$ docker-compose up
Illegal instruction: 4
$
Solution: Known issue with the Docker Toolbox on older CPUs. Install docker-compose using pip
Solution:
Solution:
php artisan key:generate
to update APP_KEY on .env, then restart the container.Solution:
docker-config.yml
to reference MySQL:
laravel:
image: reflexions/docker-laravel:latest
ports:
- 80:80
env_file: .env
links:
- database
volumes:
- .:/var/www/laravel
database: image: mysql:5.6 ports:
- Modify `.env` to reference MySQL:
```bash
# 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
MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=application MYSQL_USER=username MYSQL_PASSWORD=password
##### **Problem:** Want to use mysql already running on local machine (not docker)
_**Solution:**_
- Modify `docker-config.yml` to drop the unnecessary database service:
```yaml
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;