openjdk:8镜像中安装工具命令的方法
创始人
2024-05-27 14:24:24
0

文章目录

  • 前言
  • 一、获取openjdk:8环境
    • 1.下载并运行openjdk:8
    • 2.获取当前镜像的基础环境信息
    • 3.更换源并安装软件
  • 二、更新Dockerfile
    • 1.增加命令
    • 2.尝试构建
    • 3.测试镜像是否可用
  • 总结


前言

记录一下openjdk:8镜像安装命令的方法
同事使用openjdk:8作为基础镜像构建业务镜像,但是使用中发现镜像里面没有ping、telnet等基础命令,要求把基础命令安装进去。


一、获取openjdk:8环境

1.下载并运行openjdk:8

docker pull openjdk:8
docker run -id --name openjdk8 openjdk:8
docker exec -it openjdk8 /bin/bash

2.获取当前镜像的基础环境信息

执行命令

cat /proc/version
cat /etc/os-release 

结果如下

root@483715bfde28:/# cat /proc/version
Linux version 3.10.0-1160.81.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Fri Dec 16 17:29:43 UTC 2022
root@483715bfde28:/# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

获取到了基础镜像是debain的bullseye

3.更换源并安装软件

将源更换为清华源

cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF

安装软件

apt-get clean
apt-get update
apt-get install -y curl telnet vim iputils-ping net-tools

安装成功,问题不大,准备修改Dockerfile文件


二、更新Dockerfile

1.增加命令

Dockerfile文件中新增如下命令

RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" >/etc/apt/sources.list 
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >>/etc/apt/sources.list 
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >>/etc/apt/sources.list 
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >>/etc/apt/sources.list
RUN  apt-get clean
RUN  apt-get update
RUN  apt-get install -y curl telnet vim iputils-ping net-tools

2.尝试构建

构建命令

docker build -t test-web:v1.0 .

输出如下

[root@test test-web]# docker build -t test-web:v1.0 .
Step 1/10 : FROM openjdk:8---> b273004037cc
Step 2/10 : RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" >/etc/apt/sources.list---> Using cache---> ea5189455f8b
Step 3/10 : RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >>/etc/apt/sources.list---> Using cache---> 859b218f4aef
Step 4/10 : RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >>/etc/apt/sources.list---> Using cache---> 88a9568408ca
Step 5/10 : RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >>/etc/apt/sources.list---> Using cache---> 95f37a9b9886
Step 6/10 : RUN  bash -c 'touch /app.jar'---> Using cache---> 9e91facf1408
Step 7/10 : RUN  apt-get clean---> Using cache---> 37265a8c9f30
Step 8/10 : RUN  apt-get update---> Using cache---> 62d8593301bb
Step 9/10 : RUN  apt-get install -y curl telnet vim iputils-ping net-tools---> Using cache---> 1c0e8839109e
Step 10/10 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone---> Using cache---> c41913f5c72f
Successfully built c41913f5c72f
Successfully tagged test-web:v1.0

截图如下
在这里插入图片描述

构建完毕,测试下是否达到了预期

3.测试镜像是否可用

启动测试容器,检查服务是否安装

docker run -id --name testweb test-web:v1.0
docker exec -it testweb /bin/bash
dpkg -l |grep vpn

检查正常


总结

记录一下openjdk:8安装命令的方式,感觉最主要的还是确认基础环境的系统版本,然后切换一个好使的软件源。

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...