Docker Swarm with springboot app

人走茶凉 提交于 2020-02-07 03:40:28

问题


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


回答1:


I had the same issue but fixed after changing the port number of the spring boot service to

ports:
  - "8082:8080"

The actual issue is: tomcat server by default listening on port 8080 not the port mentioned on the compose file. Also i increased the memory limit.

FYI: The internal port of the tasks/container running in the service can be same for other containers as well(:) so mentioning 8080(internal port) for both spring boot container and visualizer container is not a problem.




回答2:


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.



来源:https://stackoverflow.com/questions/51053147/docker-swarm-with-springboot-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!