美文网首页
docker安装jdk1.8

docker安装jdk1.8

作者: 楼兰King | 来源:发表于2020-07-20 22:09 被阅读0次

    一、下载centos镜像

    docker pull centos:centos7
    

    二、下载jdk1.8并上传到/usr/local/src目录,进行解压

    cd /usr/local/src
    tar -zxvf jdk-8u221-linux-x64.tar.gz
    

    三、创建Dockerfile
    在/usr/local目录下创建jdk目录,把/usr/local/src下的jdk-8u221-linux-x64.tar.gz复制到/usr/local/jdk目录下,然后创建Dockerfile

    mkdir /usr/local/jdk
    cd /usr/local/jdk
    cp ../src/jdk-8u221-linux-x64.tar.gz ./
    vi Dockerfile
    

    Dockerfile的内容如下

    from centos:centos7
    maintainer huangbaokang
    run mkdir /usr/local/jdk
    workdir /usr/local/jdk
    add jdk-8u221-linux-x64.tar.gz /usr/local/jdk
    
    env JAVA_HOME /usr/local/jdk/jdk1.8.0_221
    env JRE_HOME /usr/local/jdk/jdk1.8.0_221/jre
    env PATH $JAVA_HOME/bin:$PATH
    

    四、使用Dockerfile构建jdk1.8镜像

    [root@localhost jdk]# docker build -t jdk1.8 .
    Sending build context to Docker daemon  195.1MB
    Step 1/8 : FROM centos:centos7
     ---> 9f38484d220f
    Step 2/8 : MAINTAINER huangbaokang
     ---> Running in f1317fbd7731
     ---> a306212c0def
    Removing intermediate container f1317fbd7731
    Step 3/8 : RUN mkdir /usr/local/jdk
     ---> Running in 66dcf152436f
     ---> 8b826710b0c9
    Removing intermediate container 66dcf152436f
    Step 4/8 : WORKDIR /usr/local/jdk
     ---> be7d7d65e5e9
    Removing intermediate container 84769a8b3d9a
    Step 5/8 : ADD jdk-8u221-linux-x64.tar.gz /usr/local/jdk
     ---> a2d9c2afc0ca
    Removing intermediate container 99717e98280f
    Step 6/8 : ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_221
     ---> Running in f752d1bbafbf
     ---> dde69d1ef725
    Removing intermediate container f752d1bbafbf
    Step 7/8 : ENV JRE_HOME /usr/local/jdk/jdk1.8.0_221/jre
     ---> Running in c11d2a27a9f9
     ---> 10974838c11a
    Removing intermediate container c11d2a27a9f9
    Step 8/8 : ENV PATH $JAVA_HOME/bin:$PATH
     ---> Running in 5b4e1204fc2d
     ---> 176a1480e95b
    Removing intermediate container 5b4e1204fc2d
    Successfully built 176a1480e95b
    Successfully tagged jdk1.8:latest
    

    五、查看构建的镜像

    [root@localhost jdk]# docker images
    REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
    jdk1.8               latest              176a1480e95b        2 minutes ago       608MB
    redis                latest              857c4ab5f029        2 weeks ago         98.2MB
    mongo                latest              f7adfc4dbcf5        2 weeks ago         413MB
    nginx                latest              e445ab08b2be        3 weeks ago         126MB
    php                  7.2-apache          e19b0ce01039        3 weeks ago         413MB
    mysql                latest              2151acc12881        3 weeks ago         445MB
    centos               centos7             9f38484d220f        5 months ago        202MB
    php                  5.6-fpm             3458979c7744        6 months ago        344MB
    jaspeen/oracle-11g   latest              0c8711fe4f0f        3 years ago         281MB
    consol/tomcat-7.0    latest              7c34bafd1150        4 years ago         601MB
    
    

    六、启动jdk容器

    [root@localhost jdk]# docker run -di --name=jdk1.8 jdk1.8
    1ab4fca37eacf244e2d89a630c7cde5bf7a3b85f5a787b7ddb7aa723d9887436
    

    七、进入jdk容器,查看版本

    [root@localhost jdk]# docker exec -it jdk1.8 /bin/bash
    [root@1ab4fca37eac jdk]# java -version
    java version "1.8.0_221"
    Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
    

    相关文章

      网友评论

          本文标题:docker安装jdk1.8

          本文链接:https://www.haomeiwen.com/subject/gvqgkktx.html