docker容器中安装软件
使用Dockerfile文件构建镜像时安装
参考文章:https://zhuanlan.zhihu.com/p/708551554
apt-get更换为清华源
https://mirrors.tuna.tsinghua.edu.cn/help/debian/
1、【sources.list】
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src 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-src 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-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bullseye-security main contrib non-free
# deb-src https://security.debian.org/debian-security bullseye-security main contrib non-free
2、创建Dockerfile
# vim Dockerfile
# docker build -t fwq-server:0.1 .
# docker run -d --restart always --name fwq-server -p 7233:7233 -p 7234:7234 -p 7235:7235 -v /home/tunnel/system:/usr/local/jar fwq-server:0.1
FROM openjdk:11.0.16-jre
ADD sources.list /etc/apt/
RUN apt-get update -y && apt-get install -y vim
RUN apt-get update -y && apt-get install -y iputils-ping
RUN apt-get update -y && apt-get install -y dnsutils
RUN apt-get update -y && apt-get install -y iproute2
MAINTAINER 295672923@qq.com
WORKDIR /usr/local/jar
VOLUME /usr/local/jar
ENV TZ Asia/Shanghai
EXPOSE 7233 7234 7235
CMD ["bash","./run.sh"]
容器内安装
1.进入docker容器
docker exec -it 容器名 /bin/bash
2.执行安装命令(apt-get 或者yum)
apt-get update && apt-get install -y vim
3.如果apt-get命令失败,则使用yum命令
4.安装一个ping命令
apt-get update && apt-get install -y iputils-ping