ref:http://blog.chengweichen.com/2016/03/docker-laravel.html
laravel資料夾權限
sudo chgrp -R www-data blog
Use Docker
MySQL
MySQL : name,volume,MYSQL_ROOT_PASSWORD,port
1 2 3 4 5 6 7
| docker run -d \ --restart=always \ --name dev_mysql \ -p 3307:3306 \ -v /home/hsu/dockerdata:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=yourpassword \ mysql:latest
|
這樣不錯 : -e
輸入的 environment variables
分別是 root 帳號的密碼、新建一個名為 homestead 的 DB、新建一個 User 並設定此 User 的 Password。
沒掛載volume刪除容器後資料就消失了。
1 2 3 4 5 6 7 8 9
| docker run -d \ --restart=always \ --name dev_mysql \ -p 3307:3306 \ -e MYSQL_ROOT_PASSWORD=yourpassword \ -e MYSQL_DATABASE=homestead \ -e MYSQL_USER=homestead \ -e MYSQL_PASSWORD=secret \ mysql:latest
|
PhpMyAdmin
PhpMyAdmin : port
1 2 3 4 5 6 7
| docker run -d \ --restart=always \ --name phpmyadmin \ --link dev_mysql \ -p 8080:80 \ -e PMA_HOST=dev_mysql \ phpmyadmin/phpmyadmin
|
ref:https://github.com/phpmyadmin/docker
PHP
Dockerfile1 2 3 4 5 6
| FROM php:7.0-fpm RUN docker-php-ext-install -j$(nproc) pdo_mysql RUN docker-php-ext-install -j$(nproc) mbstring RUN docker-php-ext-install -j$(nproc) tokenizer RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/local/bin/composer
|
docker build -t myphp:7.0-fpm .
PHP : name,link,DB_HOST,volume,workdir
1 2 3 4 5 6 7 8
| docker run -d \ --restart=always \ --name dev_phpfpm \ --link dev_mysql:db \ -e DB_HOST=dev_mysql \ -v /home/hsu/blog:/var/project \ -w /var/project \ myphp:7.0-fpm
|
Nginx
nginx.conf1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| server { listen 80 default_server; server_name lovenery.me; root /var/project/public; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } error_page 404 /index.php; sendfile off; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass dev_phpfpm:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param DB_HOST dev_mysql; } location ~ /\.ht { deny all; } }
|
Nginx : port,link,volume
1 2 3 4 5 6 7 8
| docker run -d \ --restart=always \ --name dev_nginx \ --link dev_phpfpm:phpfpm \ -p 8000:80 \ -v /home/hsu/blog:/var/project \ -v /home/hsu/nginx.conf:/etc/nginx/conf.d/default.conf \ nginx:1.9
|
Test
curl localhost:8000
docker exec dev_phpfpm php artisan
docker exec dev_phpfpm php artisan migrate
Summary 步驟
laravel new blog
sudo chgrp -R www-data blog
MySQL1 2 3 4 5 6 7 8 9
| docker run -d \ --restart=always \ --name dev_mysql \ -p 3307:3306 \ -e MYSQL_ROOT_PASSWORD=yourpassword \ -e MYSQL_DATABASE=homestead \ -e MYSQL_USER=homestead \ -e MYSQL_PASSWORD=secret \ mysql:latest
|
PhpMyAdmin1 2 3 4 5 6 7
| docker run -d \ --restart=always \ --name phpmyadmin \ --link dev_mysql \ -p 8080:80 \ -e PMA_HOST=dev_mysql \ phpmyadmin/phpmyadmin
|
php-fpm1 2 3 4 5 6 7 8
| docker run -d \ --restart=always \ --name dev_phpfpm \ --link dev_mysql:db \ -e DB_HOST=dev_mysql \ -v /home/hsu/blog:/var/project \ -w /var/project \ myphp:7.0-fpm
|
nginx1 2 3 4 5 6 7 8
| docker run -d \ --restart=always \ --name dev_nginx \ --link dev_phpfpm:phpfpm \ -p 8000:80 \ -v /home/hsu/blog:/var/project \ -v /home/hsu/nginx.conf:/etc/nginx/conf.d/default.conf \ nginx:1.9
|
Use Docker Compose
docker-compose.yml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| dev_mysql: container_name: dev_mysql restart: always image: mysql:latest ports: - "3307:3306" environment: - MYSQL_ROOT_PASSWORD=YOURPASSWORD - MYSQL_DATABASE=homestead - MYSQL_USER=homestead - MYSQL_PASSWORD=secret dev_phpmyadmin: container_name: phpmyadmin restart: always image: phpmyadmin/phpmyadmin links: - dev_mysql ports: - 8080:80 environment: - PMA_HOST=dev_mysql dev_phpfpm: container_name: dev_phpfpm restart: always image: myphp:7.0-fpm links: - dev_mysql:db environment: - DB_HOST=dev_mysql volumes: - /home/hsu/blog:/var/project working_dir: /var/project dev_nginx: container_name: dev_nginx restart: always image: nginx:1.9 ports: - "8000:80" links: - dev_phpfpm:phpfpm volumes: - /home/hsu/nginx.conf:/etc/nginx/conf.d/default.conf - /home/hsu/blog:/var/project
|
docker-compose up
docker-compose up -d
detach放在背景執行