Error running JAR on Docker-Compose

Asked

Viewed 166 times

0

Look at the error;

inserir a descrição da imagem aqui

It informs that my JAR file gave error and because of this it was not executed;

My file Docker-Compose.yml must be in error, and for lack of experience I am not being able to identify, I need help, this is my file;

version: '3'
services: 
  kwan:
      image: postgres:11.5
      network_mode: bridge
      container_name: postgres

      expose:
      - 5432
      ports:
        - 5432:5432
      environment:
          - POSTGRES_PASSWORD=root
          - POSTGRES_USER=postgres
          - POSTGRES_DB=root
      restart: unless-stopped
  springapi:
      image: openjdk:10-jre-slim
      container_name: springapi
      ports:
        - 8080:8080
      depends_on:
        - kwan
      command: ["java", "-jar", "application.jar"]

It is important to inform that my operating system is Windows 10!

This is my briefcase!

inserir a descrição da imagem aqui

I tried that way;

version: '3'
services: 
  kwan:
      image: postgres:11.5
      network_mode: bridge
      container_name: postgres

      expose:
      - 5432
      ports:
        - 5432:5432
      environment:
          - POSTGRES_PASSWORD=root
          - POSTGRES_USER=postgres
          - POSTGRES_DB=root
      restart: unless-stopped
  springapi:
      image: openjdk:10-jre-slim
      container_name: springapi
      ports:
        - 8080:8080
      depends_on:
        - kwan
      volumes:
      - dockerTest-1.0.0-SNAPSHOT.jar:/application.jar
      command: ["java", "-Dspring.profiles.active=docker-demo", "application.jar"]

But it generates this error;

$ docker-compose up
ERROR: Named volume "dockerTest-1.0.0-SNAPSHOT.jar:/application.jar:rw" is used in service "springapi" but no declaration was found in the volumes section.

I too have been like this;

version: '3'
services: 
  kwan:
      image: postgres:11.5
      network_mode: bridge
      container_name: postgres

      expose:
      - 5432
      ports:
        - 5432:5432
      environment:
          - POSTGRES_PASSWORD=root
          - POSTGRES_USER=postgres
          - POSTGRES_DB=root
      restart: unless-stopped
  jar:
      image: openjdk:8-jre-slim
      volumes:
          - ./dockerTest-1.0.0-SNAPSHOT.jar
      command: "bash" -c "java -Dspring.profiles.active=docker-demo"

But it caused this error;

$ docker-compose up
ERROR: yaml.parser.ParserError: while parsing a block mapping
  in ".\docker-compose.yml", line 18, column 7
expected <block end>, but found '<scalar>'
  in ".\docker-compose.yml", line 21, column 23
  • And your file is called dockerTest-1.0.0-SNAPSHOT.jar, where that came from application.jar?

  • I was to create a nickname for the jar, I’m still learning to handle the Docker.

  • Try to put in the volumes something like "./dockerTest-1.0.0-SNAPSHOT.jar:/application.jar" and in command also put /application.jar

  • gerou erro:&#xA;&#xA;springapi | Error: Could not find or load main class .application.jar&#xA;springapi | Caused by: java.lang.ClassNotFoundException: /application/jar&#xA;springapi exited with code 1

1 answer

1

Try changing the "command" in the jar service to:

command: ["java", "-Dspring.profiles.active=docker-demo", "-jar", "application.jar"]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.