目录
第一章.Nginx镜像
1.1安装环境部署
1.2.nginx镜像容器的配置
第二章.php镜像的安装部署
2.1.文件配置
第三章.mysql镜像的安装部署
3.1.文件配置
第四章.配置网页
4.1.进入容器mysql
4.2.浏览器访问:
第一章.Nginx镜像
1.1安装环境部署
systemctl stop firewalld
setenforce 0
docker network create --subnet=172.18.0.0/16 --opt "com.docker.network.bridge.name"="docker1" mynetwork #设置网段
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
wget http://nginx.org/download/nginx-1.12.0.tar.gz
宿主机IP 192.168.233.100
安装docker
#安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2#yum-utils:提供了 yum-config-manager 工具。
#device mapper: 是Linux内核中支持逻辑卷管理的通用设备映射机制,它为实现用于存储资源管理的块设备驱动提供了一个高度模块化的内核架构。
#device mapper存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
#设置阿里云镜像源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 Docker-CE并设置为开机自动启动
yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker.service
systemctl enable docker.service安装好的Docker系统有两个程序,Docker服务端和Docker客户端。
其中Docker服务端是一个服务进程,负责管理所有容器。 Docker客户端则扮演着Docker服务端的远程控制器,可以用来控制Docker的服务端进程。
大部分情况下Docker服务端和客户端运行在一台机器上。
如果配置不够清查询前面博客内容
1.2.nginx镜像容器的配置
cd /opt
mkdir nginx
cd nginx
下载nginx安装包以1.20.2为例
上传 nginx-1.20.2.tar.gz、wordpress-4.9.4-zh_CN.tar.gz 到 /opt/nginx/ 目录中
mkdir /opt/nginx/html
tar zxvf wordpress-4.9.4-zh_CN.tar.gz -C /opt/nginx/htmlvim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <cnm>
RUN yum -y update
RUN yum -y install gcc gcc-c++ make zlib-devel pcre-devel
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.20.2.tar.gz /opt/
WORKDIR /opt/nginx-1.20.2
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
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]
docker build -t nginx:centos .
这已经是成了。这回还没开启
docker ps -a|grep nginx
docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html --net mynetwork --ip 172.18.0.10 nginx:lnmp
第二章.php镜像的安装部署
2.1.文件配置
cd /opt
mkdir php
cd /php
下载php安装包
cp php-7.1.10.tar /opt/php/
vim Dockerfile
FROM centos:7.4.1708
ENV TIME_ZOME Asia/Shanghai
ARG WJ="php-7.1.10"
ADD $WJ.tar.bz2 /opt
RUN yum -y install gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel bison \
&& mkdir -p /usr/local/php/etc \
&& cd /opt/$WJ \
&& ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-gd --with-mysqli \
--with-openssl --with-zlib --with-curl \
--with-jpeg-dir --with-png-dir --with-iconv \
--enable-fpm --enable-zip --enable-mbstring \
&& make -j 2 \
&& make install \
&& cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf \
&& cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf \
&& sed -i '/;daemonize/a\daemonize = no' /usr/local/php/etc/php-fpm.conf \
&& sed -i 's/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.d/www.conf \
&& echo "${TIME_ZOME}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime \
&& rm -rf /opt/local/php* \
&& yum clean all \
&& yum -y remove gcc gcc-c++ make \
&& mkdir -p /usr/local/nginx/html \
&& echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.phpWORKDIR /usr/local/php/
EXPOSE 9000
CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"]
docker build -t php:centos .
这里是要先开启nginx,跟mysql
docker run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --net mynetwork --ip 172.18.0.30 php:lnmp
第三章.mysql镜像的安装部署
3.1.文件配置
cd /opt
mkdir mysql
cd mysql
下载安装包
vim Dockerfile
FROM centos:7
MAINTAINER this is mysql image <wahaha>
RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make
ADD mysql-boost-5.7.20.tar.gz /usr/local/src/
WORKDIR /usr/local/src/mysql-5.7.20/
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_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=boost \
-DWITH_SYSTEMD=1 && make && make install
ADD my.cnf /etc/
ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
RUN useradd -M -s /sbin/nologin mysql
RUN chown mysql:mysql /etc/my.cnf
RUN chown -R mysql:mysql /usr/local/mysql/
RUN /usr/local/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
EXPOSE 3306
CMD ["/usr/local/mysql/bin/mysqld"]
vim my.cnf
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock[mysql]
port = 3306
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 = 1sql_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
docker build -t mysql:centos .
docker run --name=mysql -d --privileged -v /usr/local/mysql --net mynetwork --ip 172.18.0.20 mysql:lnmp
第四章.配置网页
4.1.进入容器mysql
docker exec -it mysql /bin/bash #进去容器mysql
mysql -u root -p #没密码
create database wordpress;
grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
flush privileges;
4.2.浏览器访问:
http://192.168.233.199/wordpress/index.php这边由于在nginx里面,配置文件没有配置wordpress-4.9.4-zh_CN.tar.gz ,所以这边网页不能打开。解决方法是配置文件加入ADD他的部分之后重新build,开启容器服务