在docker器皿布署web运用LNMP网络服务器自然环境

阅读  ·  发布日期 2021-01-05 10:29  ·  admin

原题目:在docker器皿布署web运用LNMP网络服务器自然环境

镜像系统免费下载

[ ~]# docker pull nginx

[ ~]# docker pull mysql

[ ~]# docker pull php:7.1.0-fpm

撰写转化成nginx器皿脚本制作

[ ~]# vim docker_nginx.sh

#!/usr/bin/env bash

docker run -p 80:80 --name nginx

-v /docker/code:/usr/share/nginx/html

-v /var/log/nginx:/var/log/nginx

-v /docker/nginx/conf.d:/etc/nginx/conf.d

--privileged=true

-d nginx

[ ~]# sh docker_nginx.sh

3e9cd3d3b97c7e5ca001b30b5905c02c616fc48a81d14f716e3242d181ce2b31

撰写转化成php器皿脚本制作

[ ~]# vim docker_php.sh

#! /usr/bin bash

docker run -p 9000:9000 --name php

-v /docker/code/:/var/www/html/

--privileged=true

-d php:7.1.0-fpm

[ ~]# sh docker_php.sh

754a8c8c860fb3650a92e011ebae9d0575209c96a429411099d143f36cc1a435

撰写转化成mysql器皿脚本制作

[ ~]# vim docker_mysql.sh

# /usr/bin bash

docker run --name mysql #建立的器皿名字

-e MYSQL_ROOT_PASSWORD=lujunwen #设定mysql登陆密码

-v /usr/lib/mysql:/usr/lib/mysql

-p 3306:3306 #器皿的3306端口号投射到寄主设备

-d mysql #后台管理运作器皿

[ ~]# sh docker_mysql.sh

63362a2f5744f962c7de19894e87624fa24579a3ca0177113f6703c8b2093250

建立新项目的文档夹和nginx配备

[ ~]# mkdir /docker/code

mkdir: 没法建立文件目录"/docker/code": 文档已存有

[ ~]# mkdir /docker/nginx/conf.d

mkdir: 没法建立文件目录"/docker/nginx/conf.d": 文档已存有

[ ~]# vim /docker/nginx/conf.d/default.conf

server {

listen 80 default_server;

server_name localhost;

root /usr/share/nginx/html/;

location / {

index index.html index.htm index.php;

autoindex off;

}

location ~ .php(.*)$ {

root /var/www/html/;

fastcgi_pass 172.17.0.3:9000;

fastcgi_index index.php;

fastcgi_split_path_info ^((?U).+.php)(/?.+)$;

fastcgi_param _FILENAME $document_root$fastcgi__name;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

include fastcgi_params;

}

}

重新启动Nginx器皿

[ ~]# docker restart nginx

nginx

开展检验

建立index文档

[ ~]# echo " ?php phpinfo; ? " /docker/code/index.php

检测,取得成功后出現

该php镜像系统,不包含pdo_mysql拓展,必须自主安裝,安裝方式以下

docker exec -it php bash

apt-get -y update

apt-get install -y libpng12-dev libjpeg-dev libpq-dev libxml2-dev

docker-php-ext-install pdo_mysql pdo_pgsql

假如要想应用redis拓展

pecl install redis-3.1.1

docker-php-ext-enable redis

进到器皿bash并进到mysql指令行

[ docker]# docker exec -it mysql bash

:/# mysql -uroot -p lujunwen

docker器皿mysql

Myslq设定登陆密码方式二

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -d mysql回到凡科,查询大量