Docker-tomcat-nginx reverse proxy and load balancing

Source: Internet
Author: User
Tags nginx reverse proxy docker ps

1. Deploy the tomcat image # to download the official Tomcat image.sudo docker pull tomcat:7-jre7#启动docker容器, 2 instances, mapping different port numbers, #~/work/sample-webapps/[v1.0|v2.0]/the Javaweb.war package below, mapped to the Docker image by volume wayDocker run-it--rm-p 8080:8080-v ~/work/sample-webapps/v1.0:/usr/local/tomcat/webapps/tomcat:7-jre7
Docker run-it--rm-p 8081:8080-v ~/work/sample-webapps/v2.0:/usr/local/tomcat/webapps/tomcat:7-jre7Once the boot is complete, you have access to two Tomcat services. 192.168.5.109 is the IP of the Docker host,8080 and 80,812 ports to start two containers, respectively, corresponding to the different version number, easy to identify. Access to Javaweb application via port mapping 1.1 manage Docker container inside # View current Docker container, use 4-bit ID to go inside Docker containerDocker PS# find the corresponding container ID

Docker Exec-t-I Yourcontainername/bin/bash

  2. Configure Nginx reverse proxy and load balancer after the Nginx reverse proxy, request Dynamic Data/javaweb data, all forwarded to Tomcat processing, multiple Tomcat to form a cluster, load balancing can be achieved, V1.0 and V2.0 May show a more detailed configuration of the upstream that makes up the Tomcat cluster, and can refer to the official documentation, with Nginx forwarding requests to the servers in the Tomcat cluster by default, as well as other ways such as Ip_hash.   /////////////////////////////////////////ubuntu14.04 above sudo apt-get install Nginx version is 1.6 stable version   Startup mode Sudo/etc/init.d/nginx Start if the port is occupied, the default boot is completed after installation. Nginx Reload configuration file, do not need to restart Nginx Sudo/etc/init.d/nginx reload/etc/nginx/ nginx.conf----------------------------------------user www-data;worker_processes 4;pid /run/ nginx.pid; events {    worker_connections 768;    #  multi_accept on;}  http {     ##    # Basic Settings     ##     sendfile on;    tcp_nopush on;     tcp_nodelay on;    keepalive_timeout 65;     types_hash_max_size 2048;    # server_tokens off;      # server_names_hash_bucket_size 64;    # server_name_in_ redirect off;     include /etc/nginx/mime.types;     default_type application/octet-stream;     ##    #  logging settings    ##     access_log /var/log/nginx/ access.log;    error_log /var/log/nginx/error.log;     ##     # gzip settings    ##     gzip  on;    gzip_disable  "Msie6";      # gzip_vary  on;    # gzip_proxied any;    # gzip_comp_level  6;    # gzip_buffers 16 8k;    # gzip_http_version 1.1;    #  gzip_types text/plain text/css application/json application/x-javascript text/ xml application/xml application/xml+rss text/javascript;     ##     # nginx-naxsi config    ##    #  uncomment it if you installed nginx-naxsi    ##       #include  /etc/nginx/naxsi_core.rules;     ##     # nginx-passenger config    ##    # uncomment it  if you installed nginx-passenger    ##     # passenger_root /usr;     #passenger_ruby  /usr/bin/ruby;      ##    # virtual host configs    ##      include /etc/nginx/conf.d/*.conf;    include /etc/nginx/sites-enabled/*;      upstream docker-tomcat-cluster {      server  127.0.0.1:8080;          server 127.0.0.1:8081;     }    server {          listen 80;        server_name 192.168.5.109; #must  give the domain to match         Location /javaweb {           proxy_pass  http://docker-tomcat-cluster ;          proxy_ Redirect off;           proxy_set_header host  $host;            proxy_set_header X-Real-IP  $remote _addr;            proxy_set_header X-Forwarded-For  $proxy _add_x_forwarded_ for;         }     }}------------------- ---------------------

3.docker mirroring migration and batch deployment

sudo docker imagessudo docker save-o./tomcat7-jre7.tar CCC8Copy the tar file to another host

Docker Load-i/opt/soft_bak/tomcat7-jre7.tar

not named after import[email protected] soft_bak]# Docker imagestag on the phone.[email protected] soft_bak]# docker tag 3e7767ddd728 geektown/tomcat7-jre7[email protected] soft_bak]# Docker images

Docker-tomcat-nginx reverse proxy and load balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.