目录
一.环境准备
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
先自定义网络,再使用指定IP运行docker
是LNMP各组件处于同一网段
docker network create --subnet=172.18.0.0/16 --opt "com.docker.network.bridge.name"="docker1" mynetwork
Docker各组件的ip为:
Nginx | 172.18.0.10 |
MySQL | 172.18.0.20 |
PHP | 172.18.0.30 |
此实验所需的软件有:
nginx-1.12.0.tar
wordpress-4.9.4-zh_CN.tar
mysql-boost-5.7.20.tar
php-7.1.10.tar
二.构建Nginx镜像
1.创建nginx的工作目录
mkdir /opt/nginx
cd /opt/nginx/
2.上传 nginx-1.12.0.tar.gz、wordpress-4.9.4-zh_CN.tar.gz 到 /opt/nginx/ 目录中
3.编辑Dockerfile配置文件
vim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <wl>
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin 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/
ADD wordpress-4.9.4-zh_CN.tar.gz /usr/local/nginx/html/
RUN chmod 777 -R /usr/local/nginx/html/
EXPOSE 80
EXPOSE 443
ENTRYPOINT [ "/usr/local/nginx/sbin/nginx", "-g", "daemon off;" ]
4.准备Dockerfile文件中所需要的其他配置文件
vim nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
#