在docker中使用sqlplus

1、找个带sqlplus的镜像

从docker hub上下载https://hub.docker.com/r/sflyr/sqlplus

 docker pull sflyr/sqlplus

2、在k8s中运行

  由于该镜像启动后没有运行的程序,所以会很快退出,导致k8s一直报错:Back-off restarting failed      container.
  是因为,容器内PID为1的进程退出导致(通常用户在构建镜像执行CMD时,启动的程序,均是PID为1)

所以,该镜像不能直接使用,需要自己加工一下。
使用dockerfile重新构建一个镜像。

[root@hadoop01 dockerfiledir]# more Dockerfile
FROM sflyr/sqlplus:latest
CMD ["/bin/bash", "-ce", "tail -f /dev/null"]
[root@hadoop01 dockerfiledir]#

构建

[root@hadoop01 dockerfiledir]# docker build -t sqlplus:v20230424 .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM sflyr/sqlplus:latest
 ---> d0cab823fcdc
Step 2/2 : CMD /bin/bash -ce tail -f /dev/null
 ---> Running in b7572268d95e
 ---> f46ed69aa12d
Removing intermediate container b7572268d95e
Successfully built f46ed69aa12d

查看镜像包

结束后会生成镜像包,使用docker images查看

[root@hadoop01 dockerfiledir]# docker images
REPOSITORY                            TAG                            IMAGE ID            CREATED             SIZE
sqlplus                               v20230424                      f46ed69aa12d        About an hour ago   461 MB

保存镜像包

[root@hadoop01 ~]# docker save -o sqlplus.tar sqlplus
[root@hadoop01 ~]# ls -lrt
total 1796316
-rw-------. 1 root root 467651072 Apr 24 02:21 sqlplus.tar

此处生成的镜像包可以直接加载使用。

如果是在启动的时候执行其他脚本,则
Dockerfile为

[root@hadoop01 dockerfiledir]# more Dockerfile
FROM sflyr/sqlplus:latest
COPY ["start.sh", "/root/start.sh"]
WORKDIR /root
CMD ["/bin/bash", "./start.sh"]
[root@hadoop01 dockerfiledir]#

注意:start.sh为Dockerfile同级目录下的文件,如下

[root@hadoop01 dockerfiledir]# ls -lrt
total 456704
-rw-r--r--. 1 root root        52 Apr 24 03:53 start.sh
-rw-r--r--. 1 root root       108 Apr 24 03:58 Dockerfile
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值