docker 安装jdk
时间: 2023-08-25 15:14:02 浏览: 137
要在Docker容器中安装JDK,可以按照以下步骤进行操作:
首先,创建一个Dockerfile文件,内容如下所示:
```
FROM centos:centos7
MAINTAINER tao
# 新建目录
RUN mkdir /usr/local/jdk
WORKDIR /usr/local/jdk
# 将jdk文件拷贝到容器/usr/local/jdk/并解压
ADD jdk-8u144-linux-x64.tar.gz /usr/local/jdk
# 设置环境变量
ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_144
ENV JRE_HOME /usr/local/jdk/jdk1.8.0_144/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH $JAVA_HOME/bin:$PATH
```
然后,在/usr/local/docker/jdk文件夹下创建该Dockerfile。
接下来,构建Docker镜像。使用以下命令在终端中运行:
```
docker build -t jdk-container /usr/local/docker/jdk
```
然后,启动容器并检查JDK是否安装成功。使用以下命令在终端中运行:
```
docker run -di --name=jdk1.8 jdk-container
docker exec -it jdk1.8 /bin/bash java -version
```
通过以上步骤,您可以在Docker容器中成功安装JDK。 [1 [3<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *2* [docker安装JDK](https://blog.csdn.net/aa_xff/article/details/119323983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *3* [Docker(3)-安装jdk](https://blog.csdn.net/qq_42170691/article/details/117857126)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文