Docker容器通过宿主机安装JDK和MAVEN

1,下载jdk和maven

JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
MAVEN https://maven.apache.org/download.cgi

2,解压

tar zxvf jdk-8u161-linux-x64.tar.gz
tar zxvf apache-maven-3.5.3.tar.gz

3移动到指定目录下

mv ./jdk-8u161 /usr/local
mv ./apache-maven-3.5.3/usr/local

4, Dockerfile

FROM centos

ENV JAVA_HOME=/usr/local/jdk
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV MAVEN_HOME /usr/local/maven
ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin

CMD ["java", "-version"]
CMD ["mvn", "-v"]

5,构建镜像

docker build -t java_maven . 生成docker image。

6,启动容器

docker run -v /usr/local/jdk1.8.0_161:/usr/local/jdk -v /usr/local/apache-maven-3.5.3:/usr/local/maven --name jdk_maven java_maven
image.png

运行容器后,显示上图,表示成功。

你可能感兴趣的:(Docker容器通过宿主机安装JDK和MAVEN)