安装ngixn
1.创建dockerfile
docker pull centos:7.2.1511
创建挂载目录
mkdir -p /data/nginx/{conf,html,logs}
FROM centos:7.2.1551
#MAINTAINER 维护者信息
MAINTAINER sfx 2097416094@qq.com
#ADD 获取url中的文件,放在当前目录下
ADD http://nginx.org/download/nginx-1.14.0.tar.gz .
#RUN 执行以下命令
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
RUN useradd -M -s /sbin/nologin nginx
RUN tar -zxvf nginx-1.14.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.14.0 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module && make && make install
#EXPOSE 映射端口
EXPOSE 80
#CMD 运行以下命令
ADD run.sh /run.sh
RUN chmod 775 /run.sh
# 启动容器时执行脚本
CMD ["/run.sh"]
2.执行脚本
#!/bin/bash
/usr/local/nginx/sbin/nginx
3.生成镜像
docker build -t nginx:sfx .
4.启动容器
启动复制配置文件
docker run --rm -it --name web nginx:sfx /bin/bash
docker cp web:/usr/local/nginx/conf/nginx.conf /data/nginx/conf/nginx.conf
分别挂载:
1.配置
2.静态资源目录
3.日志
docker run -it --name web -p 80:80 -v /data/nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf -v /data/nginx/html:/usr/local/nginx/html -v /data/nginx/logs:/usr/local/nginx/logs -d nginx:sfx /bin/bash
5.创建网络
docker network create -d bridge --subnet 192.168.10.0/24 --gateway=192.168.10.1 -o parent-eth0 br1
配置负载
#gzip on;
upstream tomcats {
server 172.17.0.2:8080 weight=1;
server 172.17.0.3:8081 weight=1;
}
server {
listen 80;
# server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcats;
}
进入到/root/conf/nginx.conf 添加如下即可
https://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.104/bin/apache-tomcat-7.0.104.tar.gz