1下载jdk根据自己的系统下载对应的jdk
2以下命令启动docker容器
docker run -i -t -v /home/jdk/:/mnt/software ddc0fb7d7a72 /bin/bash
这里添加一个-v用于将宿主机的数据卷(data volume)挂载到容器中
/home/jdk/(宿主机目录):/mnt/software(docker目录)
3 查看是否挂在
[root@6ca4c624db4f software]# ll /mnt/software/
total 181192
-rw-r--r-- 1 root root 185540433 Sep 9 07:51 jdk-8u131-linux-x64.tar.gz
[root@6ca4c624db4f software]#
4 安装jdk解压到(链接:https://pan.baidu.com/s/1V9IedzGEmTqwtaM6I2hz7g 密码:t60p)
[root@6ca4c624db4f opt]# rpm -ivh jdk-8u51-linux-x64.rpm
便于查看建立符号连接
[root@6ca4c624db4f opt]# ln -s /opt/jdk1.8.0_131/ /opt/jdk
[root@6ca4c624db4f opt]# cd /opt/jdk
[root@6ca4c624db4f jdk]# ls
COPYRIGHT LICENSE README.html THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt bin db include javafx-src.zip jre lib man release src.zip
[root@6ca4c624db4f jdk]#
5打开另一个窗口提交一个新镜像
[root@VM_0_3_centos jdk]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
843ae2cbe771 ddc0fb7d7a72 "/bin/bash" 4 minutes ago Up 4 minutes elastic_hawking
[root@VM_0_3_centos jdk]# docker commit 843ae2cbe771 xiaojinlu/java
sha256:e4b867db0a43db4807b84ef305c2778ef68f55a08e3099f1313955531f1e216f
//验证
[root@VM_0_3_centos jdk]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaojinlu/java latest e4b867db0a43 5 minutes ago 538 MB
docker.io/hello-world latest 4ab4c602aa5e 37 hours ago 1.84 kB
docker.io/centos 7.2.1511 ddc0fb7d7a72 4 weeks ago 195 MB
6打开镜像
[root@VM_0_3_centos jdk]# docker run --rm xiaojinlu/java
[root@VM_0_3_centos jdk]# java -version