docker's java build environment is described in detail

  • 2020-05-24 06:34:23
  • OfStack

Build a compiled java environment with Dockerfile. Here are the implementation steps:

Includes the following packages

ubuntu jdk maven svn

2. jdk and maven need to be downloaded manually

jdk-8u51-linux-x64.gz
apache-maven-3.3.3-bin.tar.gz

3. Create an Dockerfile file with the following contents


FROM ubuntu
RUN apt-get update
RUN apt-get -y install subversion
ADD jdk-8u51-linux-x64.gz /usr/local
ADD apache-maven-3.3.3-bin.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_51
ENV M2_HOME /usr/local/apache-maven-3.3.3
ENV PATH $PATH:$JAVA_HOME/bin:$M2_HOME/bin

Simple said 1 under the meaning of the above, is based on ubuntu create a mirror, and then update software sources, and then install svn, then download jdk, maven added to the mirror, and placed in/usr local directory, I add here is a package, in constructing suitable for mirror, the system will automatically extract, and mirror inside also won't have compressed files, and then set the environment variable

4. Finally, start building the mirror

docker build -t dev .

Once the build is complete, you can use Docker images to see an extra image called dev, which is what we created. The first thing to note here is that the Dockerfile file is in the same directory as the zip you downloaded earlier, and when you run the above packaging command, make sure it is in Dockerfile's directory.

5, start,

docker run -i -t dev

After startup, enter Java, mvn, svn, if they are all installed, then you can download the code from svn in this container, then package it through maven, and then deploy it to the container containing tomcat.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: