首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dockerize java项目

Dockerize java项目
EN

Stack Overflow用户
提问于 2018-07-12 22:01:51
回答 1查看 461关注 0票数 0

我有一个使用vert.x的maven项目。我把所有的眩晕都部署在这样的主要类中:

代码语言:javascript
复制
package launcher;

import io.vertx.core.Vertx;

public class MainLauncher {

    public static void main(String[] args) {

        final Vertx vertx = Vertx.vertx();
        vertx.deployVerticle(new ImportFileVerticle());
        vertx.deployVerticle(new InsertFileVerticle()); 
        vertx.deployVerticle(new ExportFileVerticle());
    }

}

我添加了这样的Dockerfile:

代码语言:javascript
复制
FROM maven:3.3.9-jdk-8

RUN mkdir -p /opt/app
WORKDIR /opt/app

COPY pom.xml /opt/app/pom.xml
RUN mvn install
COPY . /opt/app/
RUN mvn package

EXPOSE 8080
CMD ["mvn", "exec:java"]

我在我的pom.xml中添加了这个依赖项:

代码语言:javascript
复制
<dependency>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
</dependency>

我使用以下命令构建映像:

码头建设-t我的应用程序。

我正在执行以下命令:

docker运行-p 8080:8080 -t -i myapp

一旦运行完成,问题就出现了,我输入:

http://localhost:8080/

什么都没发生。

或者,通过使用postman调用我的垂直项的url (localhost: 8081 / listImport)来查看我的导入列表,什么也不会发生。

注: ImportFileVerticle收听8081,InsertFileVerticle收听8082,ExportFileVerticle收听8083

一旦码头图像启动,我如何调用在这些眩晕中定义的urls?

我的第二个问题是,我有一个包含应用程序前端的对接图像,我如何将包含前端的图像与后端的图像以及包含mysql的图像进行通信?

预先感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2018-07-20 19:37:28

关于我们如何运行我们的码头集装箱:

我们在创建映像时所做的是创建一个影子jar,将所有的依赖项都放在其中,然后我们在docker映像中使用该可执行jar。为此,我们使用io.vertx.core.Launcher作为我们的主要类,然后创建一个初始化垂直线来提取我们的配置和秘密,然后生成我们需要通过vertx.deployVerticle(CLASS);运行的所有其他眩晕。

或者,如果您不想做所有这些工作,可以使用维特-码头

现在回答你的问题:

  1. -p 8080:8080这一节的停靠器运行命令声明您是端口绑定8080主机到8080在码头容器。您在上面声明您正在8081,8082,8083港口的集装箱中运行您的眩晕。如果要从主机访问它们,则必须将端口绑定到主机。
  2. 这方面有两种方法:
代码语言:javascript
复制
- Binding the containers port to the host machine via the `-p` port mapping and setting up the other containers to connect to the host ip address and designated port. _**Please note you cannot use localhost because localhost refers to the containers localhost not host.**_
- Container linking.  You could also use `--link` to create a virtual network and then link the containers that way which will create dns entries in the containers /etc/hosts file that would then put in your configuration for your services. In this case I usually use docker-compose if I'm on the same machine designating dependent containers using the `depends_on` clause. [docker-compose depends\_on](https://docs.docker.com/compose/compose-file/#depends_on)

希望这能帮上忙!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51315097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档