docker部署lnmp

发布时间:2022-07-02 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了docker部署lnmp脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一、构建自定义docker网络

二、构建nginx容器(172.18.0.10)

三、构建MySQL(172.18.0.20)

四、构建php(172.18.0.30)

五、进入数据库容器给与权限

六、浏览器访问

 

一、构建自定义docker网络

Systemctl stop firewalld 
systemctl disable firewalld
setenforce 0

docker network create --subnet=172.18.0.0/16 --opt "com.docker.network.bridge.name"="docker1"  mynetwork

docker部署lnmp

二、构建nginx容器(172.18.0.10)

1.mkdir /opt/nginx
cd /opt/nginx/
把nginx-1.12.0.tar.gz和wordPress-4.9.4-zh_CN.tar.gz安装包移进来
mkdir /opt/nginx/htML
tar zxvf wordPRess-4.9.4-zh_CN.tar.gz -C /opt/nginx/html

2.vim Dockerfile

#基于基础镜像
From centos:7
#用户信息
MaiNTAINER this is nginx image <gxd>
#添加环境包
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/noLOGin nginx
#上传nginx软件压缩包,并解压
ADD nginx-1.12.0.tar.gz /usr/local/src/
#指定工作目录
WORKDIR /usr/local/src/nginx-1.12.0
RUN ./configure 
--prefix=/usr/local/nginx 
--user=nginx 
--group=nginx 
--wITh-http_stub_status_module && make && make install
env PATH /usr/local/nginx/sbin:$PATH      #指定路径
ADD nginx.conf /usr/local/nginx/conf/     #指定修改后的nginx配置文件
ADD wordpress-4.9.4-zh_CN.tar.gz /usr/local/nginx/html/ #指定网页内容
RUN chmod 777 -R /usr/local/nginx/html/
ExpOSE 80                 #指定http端口
EXPOSE 443                #指定https端口
CMD nginx -g "daemon off;"

3.修改nginx配置文件(与php对接)
在本机或者其他主机安装nginx,把nginx配置文件移进本机
vim nginx.conf
...
location / {
            root   html;
            index  index.html index.php;
        }
...
location ~ .php$ {
            root           html;
            fastcgi_pass   172.18.0.30:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_SCRIPT_NAME;
            include        fastcgi_params;
        }
...

4.创建新镜像
docker build -t nginx:lnmp .

5.启动容器
docker run -d --name nginx -p 80:80 -m 500m --memory-swap 1g -v /opt/nginx/html:/usr/local/nginx/html --net mynetwork --ip 172.18.0.10 nginx:lnmp    #限制Nginx容器最多使用500Mb的内存和1G的Swap

docker部署lnmp

 

docker部署lnmp

docker部署lnmp

 

三、构建mySQL(172.18.0.20)

1.mkdir /opt/mysql
cd /opt/mysql
把boost_1_59_0.tar.gz和mysql-5.7.17.tar.gz移动到本目录

2.vim Dockerfile

From centos:7
MAINTAINER this is mysql image (gxd)
RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison @R_555_1512@ make
ADD mysql-5.7.17.tar.gz /opt/
ADD boost_1_59_0.tar.gz /usr/local/
WORKDIR /usr/local/
RUN mv boost_1_59_0 /usr/local/boost/
WORKDIR /opt/mysql-5.7.17/
RUN cmake 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
-DSYSCONFDIR=/etc 
-Dsystemd_PID_DIR=/usr/local/mysql 
-DDEFAULT_CHARSET=utf8  
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_EXTRA_CHARSETS=all 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ArchIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 
-DMYSQL_DATADIR=/usr/local/mysql/data 
-DWITH_BOOST=/usr/local/boost 
-DWITH_SYSTEMD=1 && make -j4 && make install
RUN useradd -M -s /sbin/nologin mysql
ADD my.cnf /etc/
RUN chown -R mysql:mysql /usr/local/mysql/
RUN chown mysql:mysql /etc/my.cnf
ENV PATH /usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql/bin/
RUN ./mysqld 
--initialize-insecure 
--user=mysql 
--basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data
RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
EXPOSE 3306
RUN systemctl enable mysqld
VOLUME [ "/usr/local/mysql" ]   #建立数据卷让mysql与php对接
CMD ["/usr/sbin/init"]

3.在当前目录创建mysql配置文件
vim my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

4.创建新镜像
docker build -t mysql:lnmp .

5.启动容器,并进行初始化
docker run --name=mysql -d --privileged --device-write-bps /dev/sda:10M -v /usr/local/mysql --net mynetwork --ip 172.18.0.20 mysql:lnmp 
docker ps -a

docker部署lnmp

docker部署lnmp

 

 

docker部署lnmp

docker部署lnmp

 

四、构建php(172.18.0.30)

1.mkdir /opt/php
cd /opt/php
上传 php-7.1.10.tar.bz2 到/opt/php目录中

2.vim Dockerfile

FROM centos:7
MAINTAINER this is php image <wl>
RUN yum -y install gd 
libjpeg libjpeg-devel 
libpng libpng-devel 
freetype freetype-devel 
libXMl2 libxml2-devel 
zlib zlib-devel 
curl curl-devel 
openssl openssl-devel 
gcc gcc-c++ make pcre-devel 
RUN useradd -M -s /sbin/nologin nginx
ADD php-7.1.10.tar.bz2 /usr/local/src/
WORKDIR /usr/local/src/php-7.1.10
RUN ./configure 
--prefix=/usr/local/php 
--with-mysql-sock=/usr/local/mysql/mysql.sock 
--with-mysqli 
--with-zlib 
--with-curl 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--with-openssl 
--enable-FPM 
--enable-mbstring 
--enable-xml 
--enable-session 
--enable-ftp 
--enable-pdo 
--enable-tokenizer 
--enable-zip && make && make install
ENV PATH /usr/local/php/bin:/usr/local/php/sbin:$PATH
ADD php.ini	/usr/local/php/lib/
ADD php-fpm.conf /usr/local/php/etc/
ADD www.conf /usr/local/php/etc/php-fpm.d/
EXPOSE 9000
CMD /usr/local/php/sbin/php-fpm -F

3.创建新镜像
docker build -t php:lnmp .

4.创建新容器
docker run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --net mynetwork --ip 172.18.0.30 php:lnmp

docker部署lnmp

 

docker部署lnmp

docker部署lnmp

 

五、进入数据库容器给与权限

docker exec -it mysql /bin/bash

mysql
create database wordpress;
grant all privileges on wordpress.* to 'wordpress'@'%' identified by '264196';
grant all privileges on *.* to 'root'@'%' identified by '264196';
flush privileges;

docker部署lnmp

 

 

 

docker部署lnmp

 

 

 

 

六、浏览器访问 

docker部署lnmp

 

脚本宝典总结

以上是脚本宝典为你收集整理的docker部署lnmp全部内容,希望文章能够帮你解决docker部署lnmp所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。