使用docker構建自己的php開發環境
前言:首先您需要獲取php7 及 nginx的映象倉庫地址,不會獲取的童鞋可以參考小編上篇文章《使用dockerfile構建自己的映象倉庫》
1.使用git pull 命令下載您要使用的docker映象
2.建立php7容器
docker run --privileged -itd --name php7 -p 9000:9000 -v /Users/mengfanmin/www:/var/www ccr.ccs.tencentyun.com/ordmeng/php7
3.建立nginx容器
docker run --privileged -itd --name nginx -p 80:80 -v /Users/mengfanmin/www:/var/www --link php7:php
ps:docker run 命令解析
1)--privileged 使用此引數會使container使用者真正的root許可權,否則container中的root只是普通使用者許可權
2)-itd -i: 以互動模式執行容器,通常與 -t 同時使用;
-t: 為容器重新分配一個偽輸入終端,通常與 -i 同時使用;
-d: 後臺執行容器,並返回容器ID;
3)--name給你的容器起一個別名
4)-p 埠對映 格式:主機埠:容器埠
5)-v 檔案目錄掛載 格式:主機目錄:容器目錄
6)--link php7:php 將php7容器與nginx容器進行連線
4.開啟php7映象docker start php7
5.開啟nginx映象docker start nginx
6.進入容器猥瑣欲為吧 docker exec -it nginx
docker exec -it php7
7.nginx域名相關配置參考
server{
listen 80;
root /var/www/admin/public;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
#rewrite ^/(.*) /index.php/$1 last;
}
location ~ \.php {
fastcgi_pass php:9000;//這裡需要改成php呦。目的是指定FastCGI伺服器監聽埠與地址
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
PS:因為nginx容器對php7容器進行了關聯。所以需要先啟動php7呦!!!
特別感謝勝哥的諄諄教誨……(^-^)
不要忘記對nginx進行相關配置呦,祝您成功666~