# docker pull nginx
# docker pull tomcat
1、 启动:
# docker run –it --name tomcatA -v /warA/:/usr/local/war tomcat /bin/bash
2、 将已经准备好的index.html文件上传至宿主机/warA文件夹中,文件如下:。
3、 修改tomcat启动页面:
# cd webapps
# cd ROOT
# cp /usr/local/war/index.html/usr/local/tomcat/webapps/ROOT/index.html
4、 启动tomcat:
# sh /usr/local/tomcat/bin/startup.sh
5、安全退出容器:Ctrl+P+Q 。
1、 启动:
# docker run –it --name tomcatB -v /warB/:/usr/local/war tomcat /bin/bash
2、 将已经准备好的index.html文件上传至宿主机/warB文件夹中,文件如下:。
3、 修改tomcat启动页面:
# cd webapps
# cd ROOT
# cp /usr/local/war/index.html/usr/local/tomcat/webapps/ROOT/index.html
4、 启动tomcat:
# sh /usr/local/tomcat/bin/startup.sh
5、安全退出容器:Ctrl+P+Q 。
# docker run --name tmp-nginx -d nginx
# docker cp tmp-nginx:/etc/nginx/nginx.conf/host/path/nginx.conf
# docker rm -f tmp-nginx
# docker inspect --format '{{.NetworkSettings.IPAddress }}' tomcatA
# docker inspect --format '{{.NetworkSettings.IPAddress }}' tomcatB
upstream webPoject {
server 172.18.0.2:8080;
server 172.18.0.3:8080;
}
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm;
add_header Cache-Control 'no-store';
client_max_body_size 100m;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_valid 200 1m;
proxy_pass http://webPoject;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
可参考:
docker run --name mynginx -p 9999:80 -v/host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx