带有Springboot应用程序的Docker Swarm [英] Docker Swarm with springboot app

查看:244
本文介绍了带有Springboot应用程序的Docker Swarm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在3个虚拟机中使用docker swarm部署应用程序,我正在通过docker-compose进行创建镜像,我的文件如下:



Dockerfile:

  FROM openjdk:8-jdk-alpine 
WORKDIR / home
ARG JAR_FILE
ARG PORT
VOLUME / tmp
COPY $ {JAR_FILE} /home/app.jar
EXPOSE $ {PORT}
ENTRYPOINT [ java, -Djava.security.egd = file:/ dev /./ urandom,-jar, / home / app.jar]

和我的docker-compose是:

  version:'3'
服务:
service_colpensiones:
构建:
上下文:./colpensiones-servicio
dockerfile:Dockerfile
args:
JAR_FILE:ColpensionesServicio.jar
端口:8082
数量:
-数据:/ home
端口:
-8082:8082
数量:
数据:

我正在使用命令docker-compose up -d --build to bu镜像后,我会自动创建一个容器,以后将其删除。要使用docker swarm,我需要使用3台机器,一个管理器和两个工人,我还有另一个文件来部署具有3个副本的服务

 版本: 3 
服务:
service_colpensiones:
图像:deploy_lyra_colpensiones_service_colpensiones
部署:
副本:5
资源:
限制:
cpus: 0.1
内存:50M
restart_policy:
条件:发生故障时
卷:
-数据:/ home
端口:
-8082:8082
网络:
-网络
可视化工具:
图像:dockersamples / visualizer:稳定
端口:
- 8080:8080
卷:
- /var/run/docker.sock:/var/run/docker.sock
部署:
位置:
约束:[node.role ==经理]
网络:
-网络
网络:
网络:
数量:
数据:

到目前为止墨水一切都很好,因为在控制台中使用以下命令:docker service ls我看到创建的服务,查看器dockersamples / visualizer:稳定,向我正确显示了端口8080上的节点,但是当我要向URL请求时服务的方式如下:



curl -4



我正在关注Docker教程:入门 https://docs.docker.com/get-started/part5/



希望您的帮助,谢谢

解决方案

我的应用程序也遇到了同样的问题。我通过从Dockerfile => -Djava.security.egd = file:/ dev /./ urandom java cmdline属性中删除来重建了我的应用程序,它开始为我工作。 / p>

请检查当时为您提供服务的 docker服务日志#containerid#(以查看容器ID运行命令 docker stack ps#servicename#),并查看如果您看到任何错误消息。



PS:我最近开始使用docker,所以可能不是专家建议。万一有帮助的话。


I'm currently trying to deploy an application with docker swarm in 3 virtual machines, I'm doing it through docker-compose to create the image, my files are the following:

Dockerfile:

FROM openjdk:8-jdk-alpine
WORKDIR /home
ARG JAR_FILE
ARG PORT
VOLUME /tmp
COPY ${JAR_FILE} /home/app.jar
EXPOSE ${PORT}
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/home/app.jar"]

and my docker-compose is:

version: '3'
services:
  service_colpensiones:
    build:
      context: ./colpensiones-servicio
      dockerfile: Dockerfile
      args:
        JAR_FILE: ColpensionesServicio.jar
        PORT: 8082
    volumes: 
     - data:/home 
    ports: 
     - 8082:8082
volumes: 
 data: 

I'm using the command docker-compose up -d --build to build the image, I automatically create the container which is deleted later. To use docker swarm I use the 3 machines, one manager and two worker, I have another file to deploy the service with 3 replicas

version: '3'
services:
  service_colpensiones:
    image: deploy_lyra_colpensiones_service_colpensiones
    deploy:
     replicas: 5
     resources:
       limits:
         cpus: "0.1"
         memory: 50M
     restart_policy:
       condition: on-failure
    volumes: 
     - data:/home 
    ports: 
     - 8082:8082
    networks:
      - webnet
  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - webnet
networks:
  webnet: 
volumes: 
 data:

So far I think everything is fine because in the console with the command: docker service ls I see the services created, the viewer dockersamples / visualizer: stable, shows me the nodes correctly on port 8080, but when I want to make a request to the url of the services that is in the following way:

curl -4 http://192.168.99.100:8082/colpensiones/msg

the error appears: curl: (7) Failed to connect to 192.168.99.100 port 8082: Refused connection.

The images from service are:

I am following the docker tutorial: Get Started https://docs.docker.com/get-started/part5/

I hope your help, thanks

解决方案

I also faced the same issue for my application. I rebuilt my app by removing from Dockerfile => -Djava.security.egd=file:/dev/./urandom java cmdline property, and it started working for me.

Please check "docker service logs #containerid#" (to see container ids run command "docker stack ps #servicename#") which served you request at that time, and see if you see any error message.

PS: I recently started on docker, so might not be an expert advice. Just in case if it helps.

这篇关于带有Springboot应用程序的Docker Swarm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆