使用openjdk:8和openjdk:11作为基础镜像构建业务镜像,但是使用中发现镜像里面没有ping、telnet等基础命令
在容器中使用: 将源更换为清华源 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中使用: 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
alpine安装telnet、curl等命令 很多镜像是使用alpine作为基础镜像,体积小,但apline精简了很多基础组件因此调试起来很麻烦,下方总结了常用的alpine组件安装方法:
功能
命令
备注
镜像加速
sed -i ‘s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g’ /etc/apk/repositories
将原装的alpine库替换成国内的ustc库
apk库更新
apk update
安装curl
apk add curl
安装telnet
apk add busybox-extras
偷懒N合1
sed -i ‘s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g’ /etc/apk/repositories && apk update && apk add curl && apk add busybox-extras