- 准备需要的镜像
- NGINX
- tomcat:8.5.0(使用最新版的看不到Tomcat主页,所以就用这个版本了)
- 准备nginx.conf配置文件,下一步需要挂载到nginx容器中(t01和t02待会创建Tomcat容器时挂载使用该别名,也可以更改)
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; #include /etc/nginx/conf.d/*.conf; upstream tomcat_client { server t01:8080 weight=1; server t02:8080 weight=1; } server { server_name ""; listen 80 default_server; listen [::]:80 default_server ipv6only=on; location / { proxy_pass http://tomcat_client; proxy_redirect default; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } }
-
编写docker-compose.yml文件
version: "3" services: tomcat001: image: tomcat:8.5.0 ports: - "8083:8080" restart: "always" container_name: tomcat001 tomcat002: image: tomcat:8.5.0 ports: - "8082:8080" container_name: tomcat002 restart: "always" nginx: image: nginx volumes: - /root/componse_test/tomcat/nginx/nginx.conf:/etc/nginx/nginx.conf ports: - "81:80" - "443:443" links: - tomcat001:t01 - tomcat002:t02
-
如果要区分的话可以挂载自定义index.jsp到Tomcat容器中的/usr/local/tomcat/webapps/ROOT/ 该目录下
-
然后使用docker-compose up -d 启动即可
转载于:https://my.oschina.net/xpx/blog/1845532