docker容器中安装软件

使用Dockerfile文件构建镜像时安装

参考文章:https://zhuanlan.zhihu.com/p/708551554
apt-get更换为阿里云源
https://developer.aliyun.com/mirror/debian

1、【sources.list】

deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib

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

posted @ 2022-09-10 10:20  黄河大道东  阅读(36)  评论(0)    收藏  举报