[英]Docker and Java IDE integration
I'll start by saying that I'm not a Java developer and also I'm not a Docker expert. 我首先要说的是,我不是Java开发人员,也不是Docker专家。
In order to minimize the gap between frontend and backend (in this specific case, Java) developers I started to put some docker images in place with java and maven and after the build I start a docker container with a volume pointing to the java project (and frontend developers don't have to worry about dependencies or how to run backend services). 为了最小化前端和后端之间的差距(在这个特定情况下,Java)开发人员,我开始用java和maven放置一些docker镜像,在构建之后,我启动一个带有指向java项目的卷的docker容器(和前端开发人员不必担心依赖关系或如何运行后端服务)。
Already here I have a question. 我已经有了一个问题。 I've seen other people building an image with the actual code inside instead of attaching it later, so what's the best case (if there's one)? 我见过其他人用内部实际代码构建图像而不是稍后附加它,那么最好的情况是什么(如果有的话)? I've done this way since I can reuse that image for "every" project and avoid building different images. 我已经这样做了,因为我可以将该图像重用于“每个”项目并避免构建不同的图像。
For starting/stopping/restarting docker containers I created a script that does all of that, so I can make some changes to the code, bring it down and up again. 为了启动/停止/重新启动docker容器,我创建了一个完成所有这些操作的脚本,因此我可以对代码进行一些更改,然后将其重新启动。
It kinda works, and what I mean is, I'm well aware this is not a normal workflow of a Java developer to do that kind of stuff from a console. 它有点工作,我的意思是,我很清楚这不是Java开发人员从控制台做这种东西的正常工作流程。 So now, to the most important question, how do you integrate docker with a Java IDE? 那么现在,对于最重要的问题,如何将docker与Java IDE集成? I know that you can create custom build/run commands but I also read that things like logs are not displayed on the IDE's. 我知道您可以创建自定义构建/运行命令,但我还读到IDE之类的日志不会显示。
Can someone explain me how are you using Docker + Java IDE's? 有人可以解释我你是如何使用Docker + Java IDE的?
Note: Maven is also used for compiling java code, like mvn clean install
(if this helps) 注意:Maven也用于编译java代码,比如mvn clean install
(如果这有帮助的话)
I do not use Docker with a Java IDE. 我不使用Docker和Java IDE。 I use the IDE (Eclipse) to write and test the code, with Maven to manage the build. 我使用IDE(Eclipse)编写和测试代码,使用Maven来管理构建。 Then I have a Dockerfile
like this: 然后我有一个像这样的Dockerfile
:
FROM java:8
RUN apt-get update || apt-get update
RUN apt-get install -y maven
# Maven installs Java 7, which set itself as the default...
RUN update-alternatives --remove java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
CMD java -jar target/main.jar
# Pull down dependencies here to allow Docker to cache more
ADD pom.xml /opt/app/pom.xml
WORKDIR /opt/app
RUN mvn dependency:go-offline -X
# I use the maven-shade-plugin to build a single jar
ADD src /opt/app/src
RUN mvn package
If you build all your images on one machine, then Docker will cache intelligently and you don't need to do anything more. 如果您在一台计算机上构建所有图像,那么Docker将智能缓存,您无需再执行任何操作。 If you want to run across more machines, or you just want to make it explicit, you could do something like this: 如果你想要运行更多的机器,或者你只想让它明确,你可以这样做:
base/Dockerfile
: base/Dockerfile
:
FROM java:8
RUN apt-get update || apt-get update
RUN apt-get install -y maven
RUN update-alternatives --remove java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
CMD java -jar target/main.jar
$ docker build -t yourorg/java-base:8 ./base/ $ docker build -t yourorg / java-base:8 ./base/
myapp/Dockerfile
: myapp/Dockerfile
:
FROM yourorg/java-base:8
ADD pom.xml /opt/app/pom.xml
WORKDIR /opt/app
RUN mvn dependency:go-offline -X
ADD src /opt/app/src
RUN mvn package
You don't get as big an effect from Docker with Java, because JARs are already pretty portable and well-contained. 你没有从Docker获得与Java一样大的效果,因为JAR已经非常便携且包含得很好。 I suppose it makes it easy to run different Java versions side-by-side. 我想它可以很容易地并排运行不同的Java版本。 I use it because it allows me to run applications in different languages without needing to know what's inside the container. 我使用它是因为它允许我以不同的语言运行应用程序而无需知道容器内的内容。 I have some in Java, some in Python, some in JavaScript, some in Erlang, but they all get started as docker run -d <flags> myorg/myimage:someversion
. 我有一些用Java,有些在Python,有些用在Erlang,但是它们都是以docker run -d <flags> myorg/myimage:someversion
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.