#安裝docker 默認已安裝docker,安裝地址:https://www.docker.com/php
1.下載php 和nginx鏡像html
docker pull php docker pull nginx
2.建立dockerfile, dockerfile 是由一系列命令和參數構成的腳本,這些命令應用於基礎鏡像並最終建立一個新的鏡像。 #touch Dockerfilemysql
建立phpdockerfile文件夾,建立Dockerfile文件。nginx
FROM php:5.6-fpm RUN apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libmcrypt-dev \ libpng12-dev \ && docker-php-ext-install -j$(nproc) iconv mcrypt \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd RUN docker-php-ext-install mbstring RUN docker-php-ext-install mysqli RUN docker-php-ext-install pdo && docker-php-ext-install pdo_mysql
運行build 建立鏡像web
docker build -t pdophp . //(pdophp)表明新鏡像名非固定,(.) 表明當前目錄 docker自動去找Dockerfile文件
3.根據新建立的pdophp鏡像,創建容器互連php與nginx。並創建文件映射sql
//myphp 容器名(非固定),workend 網絡組名稱(非固定),/Users/xxx/Works/web/工做目錄(非固定) docker run --name myphp --net workend -v /Users/xxx/Works/web/:/var/www/html/ --privileged=true -d pdophp
//mynginx容器名(非固定),workend網絡組名稱(同名互連),/Users/xxx/Works/web 工做目錄(非固定),/Users/xxx/Works/docker/nginx/conf.d/ nginx配置文件(非固定) docker run --name mynginx -p 80:80 --net workend -v /Users/xxx/Works/web:/usr/share/nginx/html -v /Users/xxx/Works/docker/nginx/conf.d/:/etc/nginx/conf.d --privileged=true -d nginx
4.創建nginx配置文件docker
運行 docker ps
查看myphp容器端口(ports),個人爲9000thinkphp
在/Users/xxx/Works/docker/nginx/conf.d/下建立default.conf瀏覽器
server { listen 80 default_server; server_name _; root /usr/share/nginx/html; location / { index index.html index.htm index.php; autoindex off; } location ~ \.php(.*)$ { root /var/www/html/; fastcgi_pass myphp:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
重啓mynginx網絡
docker restart mynginx
在/Users/xxx/Works/web/ 下建立info.php
<?php phpinfo();
打開瀏覽器訪問,http://localhost/info.php
成功繼續往下,不成功找緣由...
以後把thinkphp項目放到/Users/xxx/Works/web/下,如phpshop 訪問http://localhost/phpshop 在/Users/xxx/Works/docker/nginx/conf.d/下建立每一個項目的專屬nginx配置。配置以後要重啓mynginx
偶爾容器關閉了,使用docker start myphp
啓動,先啓動myphp再啓動mynginx
參考:
http://blog.csdn.net/qq_28602957/article/details/53727865
http://www.tuicool.com/articles/AVZFZ3m
http://www.open-open.com/lib/view/open1435818241325.html
...等等等等