下載本身須要的版本TAG,詳見:html
docker安裝指定版本TAG的鏡像linux
$ sudo docker pull centos:centos7
$ sudo cd /usr/local/src $ sudo tar zxf jdk-8u201-linux-x64.tar.gz $ sudo ls jdk1.8.0_201 jdk-8u201-linux-x64.tar.gz
先在/usr/local目錄下建立jdk目錄,並將/usr/local/src下的jdk-8u201-linux-x64.tar.gz複製到/usr/local/jdk目錄下,而後建立Dockerfile文件docker
$ sudo mkdir /usr/local/jdk $ sudo cd /usr/local/jdk $ sudo cp ../src/jdk-8u201-linux-x64.tar.gz ./ $ sudo ls jdk-8u201-linux-x64.tar.gz $ sudo vi Dockerfile FROM centos:centos7 MAINTAINER tom RUN mkdir /usr/local/jdk WORKDIR /usr/local/jdk ADD jdk-8u201-linux-x64.tar.gz /usr/local/jdk ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_201 ENV JRE_HOME /usr/local/jdk/jdk1.8.0_201/jre ENV PATH $JAVA_HOME/bin:$PATH
$ sudo docker build -t jdk1.8 . Sending build context to Docker daemon 191.8MB Step 1/8 : FROM centos:centos7 ---> 9f38484d220f Step 2/8 : MAINTAINER tom ---> Running in 9ebabac7e9e0 Removing intermediate container 9ebabac7e9e0 ---> 6e65e30640c0 Step 3/8 : RUN mkdir /usr/local/jdk ---> Running in 5805a4f50285 Removing intermediate container 5805a4f50285 ---> 8ebaedf8bd72 Step 4/8 : WORKDIR /usr/local/jdk ---> Running in c68e7f94ce6d Removing intermediate container c68e7f94ce6d ---> f4df19bf9468 Step 5/8 : ADD jdk-8u201-linux-x64.tar.gz /usr/local/jdk ---> 1fa5d55acc2e Step 6/8 : ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_201 ---> Running in c9c93a299d59 Removing intermediate container c9c93a299d59 ---> 09b5bfd906dc Step 7/8 : ENV JRE_HOME /usr/local/jdk/jdk1.8.0_201/jre ---> Running in d4509f0c2af8 Removing intermediate container d4509f0c2af8 ---> 1d6b070b3985 Step 8/8 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in 190dde73be87 Removing intermediate container 190dde73be87 ---> 50016b7aac0c Successfully built 50016b7aac0c Successfully tagged jdk1.8:latest
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE jdk1.8 latest 50016b7aac0c 10 seconds ago 598MB
$ sudo docker run -di --name=jdk1.8 jdk1.8 e04f670691cd301b28fb56c25b12eae4851f583fa7abac367164a0ee68ad7241
$ sudo docker exec -it jdk1.8 /bin/bash [root@7d539233feb0 jdk]# pwd /usr/local/jdk [root@7d539233feb0 jdk]# ls jdk1.8.0_201