Original URL: Docker series--Methods to install JDK in containers (with examples)_IT Knives Out Blog-CSDN Blog
Introduction
illustrate
This article describes how to install JDK in a container.
Why install JDK?
There are many tools in the JDK, such as jps, jstack, jmap, etc., that can troubleshoot problems.
Objective of this article
To install JDK8 on the docker container in the Ubuntu system, you can call its jps command.
1. Determine the Linux architecture
You can use this command to check whether the architecture is x86 or arm:
uname -m
result:
2. Download JDK
Download address: https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html
The previous step confirmed that the system is x86, 64-bit, so download this:
3. Copy JDK to the host machine
Copy it to this path and decompress it: /work/tool/jdk
The result is as follows:
4. Copy the host JDK to the container
Copy this path to the container: /tool
The command is:
docker cp /work/tool/jdk/jdk1.8.0_341 <容器名字或ID>:/tool
Note: The container must be a first-level directory, otherwise an error will be reported. (Of course, first go to create a new path, then you can specify multi-level directories)
5. Set environment variables
Add the following content at the end of the ~/.bashrc file:
export JAVA_HOME=/tool/
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
Methods as below:
1. Back up the ~/.bashrc file
cp ~/.bashrc ~/.bashrc.bak
2. Append variables to the ~/.bashrc file
echo "
export JAVA_HOME=/tool/
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH" >> ~/.bashrc
3. Make the new configuration take effect
source ~/.bashrc
6. Test
Test using jps: