Docker-compose scale up Jetty with NGINX at runtim

2019-07-12 19:51发布

问题:

I am new to docker. I have gone through few tutorial to create docker compose file to create 3 Jetty, 1 NGINX and 1 MySQL. NGINX is acting as LB with round robin mechanism.It is working good as expected.

If I scale up my jetty instance ( by docker-compose scale jetty-one=2), container is created . But it is not coming under NGINX LB. I hope, I have hard coded in NGINX's configuration file upstream. please guide me and provide solution for adding Jetty instance under LB at run time without restart LB.

Docker Compose

lb:
  image: nginx
  ports:
   - "82:80"
  volumes:
   - /home/docker/default.conf:/etc/nginx/conf.d/default.conf
  links:
   - jetty-one:jetty1
   - jetty-two:jetty2
   - jetty-three:jetty3
jetty-one:
  image: jetty
  volumes:
   - /home/docker/webapps:/var/lib/jetty/webapps
jetty-two:
  image: jetty
  volumes:
   - /home/docker/webapps:/var/lib/jetty/webapps
jetty-three:
  image: jetty
  volumes:
   - /home/docker/webapps:/var/lib/jetty/webapps
db:
 image: mysql
 ports:
  - "3307:3306"

NGINX config file

upstream backend  {
  server jetty1:8080;
  server jetty2:8080;
  server jetty3:8080;
}



server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        proxy_pass  http://backend;
    }


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;