目录
4.2 配置 php-fpm.conf php.ini www.conf
一. 环境准备
关闭防火墙和核心防护
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命令是用来创建一个新的自定义网络,并指定一些网络配置参数。具体分析如下:
docker network create: 这是创建一个新的Docker网络的命令。
--subnet=172.18.0.0/16: 指定网络的子网范围。这里设置为172.18.0.0开始,掩码为16位,意味着该网络支持65,536个IP地址(从172.18.0.1到172.18.255.254)。Docker会在这个子网范围内分配IP给连接到这个网络的容器。
--opt "com.docker.network.bridge.name"="docker1": 这是一个自定义网络桥接选项,用来设置网络桥接接口的名字。这里将其命名为docker1。这意味着当网络创建后,Docker会在宿主机上创建一个名为docker1的网络接口,通过这个接口容器可以与外部网络通信。这个选项允许用户自定义网络接口名称,便于管理和识别。
mynetwork: 这是新创建的网络的名称,后续可以在运行Docker容器时通过--network=mynetwork参数指定容器加入到这个网络中。
综上所述,整个命令的作用是创建一个名为mynetwork的Docker网络,该网络使用172.18.0.0/16作为子网,并且在网络桥接到宿主机时,桥接接口被命名为docker1。这样的配置为容器提供了隔离的网络环境,并允许用户通过指定的子网和网络接口名称进行更细粒度的网络管理。
二. 部署 nginx
容器IP为 172.18.0.10
具体实现操作:
mkdir /opt/nginx
cd /opt/nginx/
上传 nginx-1.12.0.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/html
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;" ]
docker build -t nginx:lnmp .
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
2.1 建立工作目录,并上传需要的安装包
2.2 配置 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" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html 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 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 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;
}
# deny access to .htaccess files, if Apache's document root
# concurs