Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Boot REST应用程序中使用Docker和Docker compose_Java_Spring_Spring Boot_Docker_Docker Compose - Fatal编程技术网

Java 在Spring Boot REST应用程序中使用Docker和Docker compose

Java 在Spring Boot REST应用程序中使用Docker和Docker compose,java,spring,spring-boot,docker,docker-compose,Java,Spring,Spring Boot,Docker,Docker Compose,我一直在阅读Docker以及如何使用它运行Spring应用程序。我了解到,在Docker的案例中,我们使用Docker引擎(而不是来宾操作系统),这是操作系统的一个非常薄的层,容器可以向下与主机操作系统对话,以获得那里的内核功能。这使得我们有一个非常轻的容器 这种说法是有道理的 我希望有一个非常基本的设置,并为我正在开发的springboot和MySQL应用程序使用Docker。应用程序本身运行良好(没有Docker)。提供了项目结构 首先,我运行$mvn clean包 这将在/target目

我一直在阅读Docker以及如何使用它运行Spring应用程序。我了解到,在Docker的案例中,我们使用Docker引擎(而不是来宾操作系统),这是操作系统的一个非常薄的层,容器可以向下与主机操作系统对话,以获得那里的内核功能。这使得我们有一个非常轻的容器

这种说法是有道理的

我希望有一个非常基本的设置,并为我正在开发的
springboot
MySQL
应用程序使用Docker。应用程序本身运行良好(没有Docker)。提供了项目结构

首先,我运行
$mvn clean包

这将在
/target
目录中创建
Appointment-0.0.1-SNAPSHOT.jar

在阅读教程之后,我定义了Dockerfile

FROM java:8
VOLUME /tmp
ADD /target/Appointment-0.0.1-SNAPSHOT.jar Appointment.jar
RUN bash -c 'touch /Appointment.jar'
ENTRYPOINT ["java","-jar","/Appointment.jar"]
下面提供了我的
docker compose.yaml
文件

version: '3'

services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    - logvolume01:/var/log

  appointment-mysql:
      container_name: appointment-mysql
      image: mysql/mysql-server:5.7
      environment:
        MYSQL_DATABASE: Appointment
        MYSQL_ROOT_PASSWORD: testpassword
        MYSQL_ROOT_HOST: '%'
      ports:
      - "3307:3307"
      restart: always

volumes:
  logvolume01: {}
我最初将MySQL的端口更改为3307。最后,我运行命令

$ docker-compose up -d
我得到了输出信息

appointment-mysql is up-to-date
Starting appointmentmanager_web_1 ... done
我看之后什么也没发生。是否有人能提供一个关于如何使用Docker和Docker compose运行Spring boot应用程序的明确说明

显然,我没有收到任何错误消息,但是,通常当我运行应用程序时, 调用一个方法并在数据库中加载一组数据

public static void main(String[] args) {

        SpringApplication.run(AppointmentApplication.class, args);
        loadAppointmentsData();
    }
我可以使用
cURL
对应用程序进行各种查询。好像少了什么东西。我知道现在学习和使用Docker已经很晚了,如果有人帮助我开始在Spring Boot应用程序中使用Docker,我真的很感激

更新

我尝试了命令
docker compose up
(不带-d),似乎没有什么错误

$ docker-compose up
appointment-mysql is up-to-date
Starting appointmentmanager_web_1 ... done
Attaching to appointment-mysql, appointmentmanager_web_1
appointment-mysql    | [Entrypoint] MySQL Docker Image 5.7.25-1.1.10
appointment-mysql    | [Entrypoint] Starting MySQL 5.7.25-1.1.10
appointment-mysql    | [Entrypoint] MySQL Docker Image 5.7.25-1.1.10
appointment-mysql    | [Entrypoint] Starting MySQL 5.7.25-1.1.10
appointment-mysql    | [Entrypoint] MySQL Docker Image 5.7.25-1.1.10
appointment-mysql    | [Entrypoint] Starting MySQL 5.7.25-1.1.10
web_1                | [INFO] Scanning for projects...
web_1                | [INFO] ------------------------------------------------------------------------
web_1                | [INFO] BUILD FAILURE
web_1                | [INFO] ------------------------------------------------------------------------
web_1                | [INFO] Total time: 0.205 s
web_1                | [INFO] Finished at: 2019-02-12T14:33:03Z
web_1                | [INFO] ------------------------------------------------------------------------
web_1                | [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
web_1                | [ERROR] 
web_1                | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
web_1                | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
web_1                | [ERROR] 
web_1                | [ERROR] For more information about the errors and possible solutions, please read the following articles:
web_1                | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
appointmentmanager_web_1 exited with code 1
因此,我认为错误主要在下面描述,这是
没有指定目标

No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
尚未为此生成指定任何目标。必须以以下格式指定有效的生命周期阶段或目标:或:[:]:。可用的生命周期阶段包括:验证、初始化、生成源、流程源、生成资源、流程资源、编译、流程类、生成测试源、流程测试源、生成测试资源、流程测试资源、测试编译、流程测试类、测试、准备包、包、预集成测试、,集成测试、集成后测试、验证、安装、部署、预清理、清理、清理后、预站点、站点、站点后、站点部署。

问题出在哪里?您的应用程序似乎正在运行,请像没有docker时那样进行测试(如果是RESTAPI,请测试healthcheck)


如果您有错误堆栈,请查看容器日志

我通常通过
cURL
测试应用程序。现在当我尝试使用时,我得到了一条消息,
$curl-I-X POST-H“Content Type:application/json”-d“{”created\u at\”:“01:12:16\,“约会日期”:“2018-10-05\,“医生姓名”:“Monika\,“price\:”122.5\”http://localhost:8080/api/v1/appointments/createAppointment 卷曲:(7)未能连接到本地主机端口8080:连接被拒绝
,对于
3307
$curl-i-X POST-H“内容类型:应用程序/json”-d“{\”创建于\\”:\“01:12:16\,“预约日期\\”:“2018-10-05\,“医生姓名\\”:“Monika\,“价格\\:“122.5\” http://localhost:3307/api/v1/appointments/createAppointment curl:(52)服务器的空回复您知道所有配置是否正确,或者如何测试应用程序属性吗?另外,在应用程序启动时,我在MySQL中放入了一堆JSON数据,这在这种情况下似乎不起作用。好的,但如果应用程序在端口8080上运行,则必须打开容器的端口8080才能访问。在web服务的docker compose中,为什么将5000:5000放在开始端口而不是8080:8080?我再次更改了
docker compose.yaml
文件和
$mvn clean package
中的端口。之后,我运行命令
$docker compose up-d
,并尝试通过
cURL
进行测试。我在终端
curl:(7)连接到本地主机端口8080失败:连接被拒绝
。因此,我的结论是,更改端口对我的情况没有影响。因为在
-d
中运行docker compose,所以没有发生任何事情。删除此选项将在容器运行时锁定您的终端,但您在终端上有更多详细信息。
No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.