1. Download the gz file of the required jdk version on the host system
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2. Copy the gz file to the root in the container
#sudo docker cp <path to jdk gz file>/jdk-8u131-linux-x64.tar.gz <container name or ID>:/root in the
user
directory In version, the docker cp command only allows copying files from the container to the host, in Docker 1.8, the Docker cp command can copy files from the host to the container.
In versions prior to Docker 1.8, use -v to mount the host data volume into the container to copy files from
the host to the container and execute in the host:
#sudo docker run --name [CONTAINER] -v /path/to/hostdir: /mnt [IMGAGE]:{TAG}
Enter the container from the host:
#sudo docker exec -it [CONTAINER] /bin/bash
Execute inside the container:
#cp /mnt/sourcefile /path/to/destfile
3. Enter the container
#sudo docker exec -it <container name or ID> /bin/bash
4. Unpack the gz file in the container
#cd ~
#tar -zxvf jdk-8u121-linux-x64.tar.gz
#chown root:root ~/jdk1.8.0_131 -R
5. Create the JAVA_HOME directory of the container system
#mkdir /usr/lib/jvm
6. Move the jdk directory to JAVA_HOME directory
#mv ~/jdk1.8.0_131 /usr/lib/jvm
7. Install vim (optional)
#apt-get update
#apt-get install vim
8. Set environment variables
#vim ~/.bashrc
export JAVA_HOME=/ usr/lib/jvm/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
9 .Make environment variables take effect immediately
#source ~/.bashrc 10.Verify
JDK version
#java -version
Install jdk 1.8 in the Docker container
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326224279&siteId=291194637
Ranking