2018年(273)
分类: 大数据
2018-06-20 15:35:38
1、首先准备两个springboot jar包,一个端口设置为8000,一个设置为8080。
2、打包第一个springboot jar包,Dockerfile如下
FROM java:8 VOLUME /tmp ADD spring-boot-docker-0.1.0.jar app.jar RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
然后运行docker构建命令
docker build -t xiao/springboot .
3、同理我们构建第二个镜像springboot2
4、构建nginx,Dockerfile如下
FROM ubuntu:latest MAINTAINER xiao ENV REFRESHED_AT 2017-03-19 RUN apt-get update RUN apt-get -y -q install nginx RUN mkdir -p /var/www/html ADD nginx/global.conf /etc/nginx/conf.d/ ADD nginx/nginx.conf /etc/nginx/nginx.conf EXPOSE 80
其中global.conf设置如下
upstream service_group{ server sample:8080 max_fails=1 fail_timeout=60s weight=1; server sample2:8000 max_fails=1 fail_timeout=60s weight=2; } server { listen 80; server_name localhost; location / { proxy_pass http://service_group; proxy_redirect default; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
nginx.conf如下
user www-data; worker_processes 4; pid /run/nginx.pid; daemon off; events { } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; }
注意daemon设置为off省的一启动就关闭容器。
5、构建nginx镜像。
6、使用 docker iamges查看镜像
7、启动两个springboot镜像