https://www.isolves.com/it/rj/czxt/windows/2020-07-28/25782.html
實現目的:windows 10下安裝Docker,布置Nginx+php5.6運行環境,布置多個docker實現負載均衡,實現成功,存在缺點windows server版本需要付費,當做測試學習,正式服務器可以考慮linux系統;
參考資料:https://www.cnblogs.com/lxd-ld/p/11578467.html?tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_IOS&utm_campaign=client_share
docker可以簡單理解為一個虛擬的的ubuntu系統,操作基本都是通過命令行來操作的,有一個虛擬的交換機接入網絡
docker與虛擬機的區別可以查看:https://zhuanlan.zhihu.com/p/74491259
獲取nginx最新版本鏡像image:
docker pull nginx
啟動一個nginx的docker,docker內部是80端口理解為端口映射到外網808端口:
docker run -d -p 808:80 --name mynginx nginx
獲取php5.6的鏡像文件:
docker pull php:5.6.40-fpm
啟動php,將宿主web目錄映射到phpweb服務器目錄,目錄與下面nginx要一致:
docker run -d -v E:dockerwww:/var/www/html -p 9000:9000 --name myphp php:5.6.40-fpm
復制docker配置文件到windows:
docker cp myphp:/usr/local/etc E:dockerphp-conf
docker cp myphp:/usr/local/var/log E:dockerphp-log
docker cp myphp:/var/www/html E:dockerwww
安裝php擴展
apt-get update
docker-php-ext-install pdo_MySQL
docker-php-ext-install mysql
docker-php-ext-install gd
docker-php-ext-install curl
php配置完成,啟動:
docker run -d -v E:dockerphp-conf:/usr/local/etc -v E:dockerphp-log:/usr/local/var/log -v E:dockerwww:/var/www/html -p 9000:9000 --name myphp php:5.6.40-fpm
復制nginx的配置到windows
docker cp mynginx:/etc/nginx E:dockernginx-conf
E:dockernginx-conf下面的nginx目錄文件都copy到上一級
按照下面修改:E:dockernginx-confconf.ddefault.conf
docker run -d -p 808:80 -v E:dockerwww:/var/www/html -v E:dockernginx-conf:/etc/nginx/ -v E:dockernginx-log:/var/log/nginx/ --link myphp:php --name mynginx nginx
到此成功success
=============================
Docker的Ubuntu鏡像安裝的容器無ifconfig命令和ping命令
進入docker命令行
docker exec -it mynginx /bin/sh
解決:
apt-get update
apt install net-tools # ifconfig
apt install iputils-ping # ping
=================================
default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/html;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
root /var/www/html;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}