配置tomcat
1, 拉取镜像
docker pull tomcat:7-jre8
2,创建Dockerfile ,制作镜像
mkdir ~/tomcat-demo
touch DockerFile
编辑内容如下
FROM tomcat:7-jre8
COPY web.xml /usr/local/bin/tomcat/conf/
touch web.xml
修改welcome页配置如下
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
3.将默认的webroot代码拷贝出来,分别在/root/tomcat/ 和 /root/tomcat2
修改html页面显示代码,显示tomcat 1和tomcat2
4.build镜像
cd /root/tomcat-demo
docker build -t localtomcat:demo .
5.启动tomcat容器
docker run -d -p 8081:8080 -v /root/tomcat1/webapps/ROOT:/usr/local/tomcat/webapps/ROOT --name tomcat-demo1 localtomcat:demo
docker run -d -p 8082:8080 -v /root/tomcat2/webapps/ROOT:/usr/local/tommkcat/webapps/ROOT --name tomcat-demo2 localtomcat:demo
配置nginx
1,拉取官网镜像
docker pull nginx
2,创建默认配置文件
mkdir -p nginx/conf.d
cd nginx/conf.d
编辑文件,ip地址为tomcat的宿主机地址,内容如下:
upstream web_app{
server 10.0.2.15:8081 weight=1 max_fails=2 fail_timeout=30s;
server 10.0.2.15:8082 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
index index.jsp index.html index.htm;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_app;
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~* .(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
3,启动nginx容器
docker run -d -p 80:80 -v /root/nginx/conf.d:/etc/nginx/conf.d --name nginx_test nginx