hj_服务器操作记录03_jdk11安装,podman运行springboot--jar包程序

主机环境安装jdk11;

官网下载:   https://www.oracle.com/java/technologies/downloads/#java11

本机是centos8 64位系统的.选择的是x64 Compressed Archive jdk-11.0.13_linux-x64_bin.tar.gz ;

上传此安装包到 /home下解压暂放. tar  zxf  jdk-11.0.13_linux-x64_bin.tar.gz 得到 jdk-11.0.13 文件目录;

拷贝此目录到 usr/local/jdk 下.  mkdir /usr/local/jdk  ;  cp  -r  /home/jdk-11.0.13  /usr/local/jdk ;

设置环境变量,配置 /etc/profile 文件, 文件尾部添加:

# JAVA11_HOME
export JAVA11_HOME=/usr/local/jdk/jdk-11.0.13 export CLASSPATH=$JAVA11_HOME/lib export PATH=$JAVA11_HOME/bin:$PATH

刷新此配置文件: source /etc/profile ;

检查是否安装成功: java   javac  java -version 

宿主机安装jdk11  over.

 

创建Dockerfile 上传springboot-jar包,运行...

[root@iZc3hwg7f2i7mfZ jdk]# cd /home/
[root@iZc3hwg7f2i7mfZ home]# mkdir hj_docker_01
[root@iZc3hwg7f2i7mfZ home]# cd hj_docker_01/
[root@iZc3hwg7f2i7mfZ hj_docker_01]# touch Dockerfile
[root@iZc3hwg7f2i7mfZ hj_docker_01]# ls
Dockerfile  hj1208-0.0.1-SNAPSHOT.jar

不使用宿主机jdk,拉取openjdk11的镜像挂载jar包..直接run 

podman run -d --privileged=true  --name hj1208  \
 -p 8888:8888 \
  -v /home/hj_docker_01/hj1208-0.0.1-SNAPSHOT.jar:/opt/hj/spring/hj1208-0.0.1-SNAPSHOT.jar \
  docker.io/openjdk:11 \
 java -jar /opt/hj/spring/hj1208-0.0.1-SNAPSHOT.jar
[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman run -d --privileged=true  --name hj1208  \
>  -p 8888:8888 \
>   -v /home/hj_docker_01/hj1208-0.0.1-SNAPSHOT.jar:/opt/hj/spring/hj1208-0.0.1-SNAPSHOT.jar \
>   docker.io/openjdk:11 \
>  java -jar /opt/hj/spring/hj1208-0.0.1-SNAPSHOT.jar
Trying to pull docker.io/library/openjdk:11...
Getting image source signatures
Copying blob 5e0b432e8ba9 done  
Copying blob 8fc448a0c88b done  
Copying blob e8b8f2315954 done  
Copying blob 0598fa43a7e7 done  
Copying blob a84cfd68b5ce done  
Copying blob e0d35e3be804 done  
Copying blob dbdff6e5955b done  
Copying config 0719902862 done  
Writing manifest to image destination
Storing signatures
4e7b26586e510c29107eb1d772a63616a2650430b30e2c464491d83489ce3208
[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman ps
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                   NAMES
22d7530c4ef6  docker.io/library/nginx:latest  nginx -g daemon o...  23 hours ago    Up 23 hours ago    0.0.0.0:80->80/tcp      hj_nginx
4e7b26586e51  docker.io/library/openjdk:11    java -jar /opt/hj...  10 seconds ago  Up 11 seconds ago  0.0.0.0:8888->8888/tcp  hj1208
[root@iZc3hwg7f2i7mfZ hj_docker_01]# 

配置 Dockerfile运行..还是得使用那个openjdk11...宿主机的jdk白装啦,不会用

# 基础镜像使用java
FROM docker.io/library/openjdk:11
# 作者
MAINTAINER hj
# VOLUME 容器挂载目录/tmp。
VOLUME /opt/hj/tmp
# 将jar包添加到容器中并更名为hj1209.jar
ADD hj1208-0.0.1-SNAPSHOT.jar hj1209.jar
# 时区
RUN echo "Asia/Shanghai" > /etc/localtime_bak
# 暴露端口
EXPOSE 8888
# 包前面的add命令把jar复制添加,这个touch命令的作用是修改这个文件的(访问,修改时间)为当前时间,可有可无
RUN bash -c 'touch /hj1209.jar'
# 运行jar
ENTRYPOINT ["java","-jar","/hj1209.jar"]

podman build -f Dockerfile -t hj1209   // 构建镜像

podman run -d --privileged=true --name hj1209 -p 8899:8888 ad47a314f726   //运行容器

[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman build -f Dockerfile -t hj1209 
STEP 1/8: FROM docker.io/library/openjdk:11
STEP 2/8: MAINTAINER hj
--> 33eb864a345
STEP 3/8: VOLUME /opt/hj/tmp
--> 0a42ada2327
STEP 4/8: ADD hj1208-0.0.1-SNAPSHOT.jar hj1209.jar
--> 5d6ce35f64f
STEP 5/8: RUN echo "Asia/Shanghai" > /etc/localtime_bak
--> 175296015eb
STEP 6/8: EXPOSE 8888
--> 45c1933e72a
STEP 7/8: RUN bash -c 'touch /hj1209.jar'
--> 941d542a543
STEP 8/8: ENTRYPOINT ["java","-jar","/hj1209.jar"]
COMMIT hj1209
--> ad47a314f72
Successfully tagged localhost/hj1209:latest
ad47a314f7265334011b57c5437bee9131e5325740bcbcb1d736703e54d1bad5
[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED         SIZE
localhost/hj1209           latest      ad47a314f726  42 seconds ago  732 MB
docker.io/library/redis    6.2.6       aea9b698d7d1  13 days ago     116 MB
docker.io/library/openjdk  11          0719902862f3  13 days ago     671 MB
docker.io/library/mysql    5.7.36      738e7101490b  13 days ago     454 MB
docker.io/library/mysql    8.0.27      bbf6571db497  13 days ago     521 MB
docker.io/library/nginx    latest      f652ca386ed1  13 days ago     146 MB
[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman run -d --privileged=true --name hj1209 -p 8899:8888 ad47a314f726
b94caf3b9200e26da896edd2a033e455454a43e8a63e27a9e53d7c279705b9af
[root@iZc3hwg7f2i7mfZ hj_docker_01]# podman ps 
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                   NAMES
d295faa7d6f2  docker.io/library/redis:6.2.6   redis-server /etc...  7 days ago      Up 28 minutes ago  0.0.0.0:6380->6380/tcp  hj_redis_6.2.6
22d7530c4ef6  docker.io/library/nginx:latest  nginx -g daemon o...  23 hours ago    Up 23 hours ago    0.0.0.0:80->80/tcp      hj_nginx
4e7b26586e51  docker.io/library/openjdk:11    java -jar /opt/hj...  29 minutes ago  Up 29 minutes ago  0.0.0.0:8888->8888/tcp  hj1208
b94caf3b9200  localhost/hj1209:latest                               7 seconds ago   Up 7 seconds ago   0.0.0.0:8899->8888/tcp  hj1209
[root@iZc3hwg7f2i7mfZ hj_docker_01]# 

 web浏览器访问.验证成功~

怎么使用宿主机的jdk 有待进一步研究...

 

posted @ 2021-12-16 15:39  独孤~华剑  阅读(512)  评论(0编辑  收藏  举报
独孤华剑