ASSUMING YOU HAVE DOCKER INSTALLED ON YOUR PLATFORM
https://docs.docker.com/engine/installation/
- In the project root create
.docker
folder anddocker-compose.yml
file - contents below - Create
.docker/site.conf
file with nginx setup - contents below - Add
.docker
to.gitignore
(recommended global .gitignore https://davidwalsh.name/global-gitignore) - Run
docker-compose up -d
in the root of your app, it will: - Pull 3 images: php, nginx and mysql
- Start and link 3 containers in a network
- MySql container will create the db automatically for you and it will be store in
.docker/mysql
folder, outside the container, so it persists - Make your
web
container (nginx) accessible via http://localhost:8081
-
Wrap the above steps in a sh function, so you can do that quickly for each project
-
Create a few handy aliases for docker, eg.: alias dcompose="docker-compose" alias dterm='_dterm(){ docker exec -it
docker ps -q -n=1 -f name=$1
bash; }; _dterm' -
In order to login to bash on your main app container (php) you'd do: (assuming your app folder is my_app)
dterm my_app_php
the name of the container you can check by callingdocker-compose ps
in app folder -
Setup dev domain in
/etc/hosts
// 1 docker-compose.yml
web:
image: nginx:latest
links:
- db
- php
volumes:
- .:/var/www/html
- .docker/site.conf:/etc/nginx/conf.d/default.conf
ports:
- "8081:80"
working_dir: /var/www/html
php:
image: jarektkaczyk/lara-php:7-fpm
links:
- db
volumes:
- .:/var/www/html
working_dir: /var/www/html
environment:
TERM: xterm
db:
image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: ____ROOT_PASS_HERE____
MYSQL_DATABASE: ____DB_NAME_HERE____
MYSQL_USER: ____DB_USER_HERE____
MYSQL_PASSWORD: ____DB_PASS_HERE____
TERM: xterm
volumes:
- .docker/mysql:/var/lib/mysql
ports:
- "33081:3306"
// 2 .docker/site.conf
server {
listen 80;
root /var/www/html/public;
index index.php index.html index.htm;
client_max_body_size 100m;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}