head-img Force's Blog

Docker 部署Jenkins后使用root权限apt-get安装需要软件

DevOps

创建容器

sudo docker run -dit --name=Jenkins -p 8889:8080 -p 50000:50000 --restart=on-failure -v /home/user/jenkins:/var/jenkins_home 873436f3411b

进入容器

sudo docker exec -it b75729cdb52f /bin/bash

编辑文本发现咩有vi、vim、nano,于是执行安装vim命令提示没权限

jenkins@b75729cdb52f:/$ vi text.temp
bash: vi: command not found
jenkins@b75729cdb52f:/$ vim text.temp
bash: vim: command not found
jenkins@b75729cdb52f:/$ nano text.temp
bash: nano: command not found

jenkins@b75729cdb52f:/$ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

重置root密码,提示不可以修改root密码

jenkins@b75729cdb52f:/$ passwd root
passwd: You may not view or modify password information for root.

查阅资料发现,docker进入容器可以以root身份进入(-u 0参数),退出当前容器重新进入

sudo docker exec -u 0 -it b75729cdb52f /bin/bash

这样进入就有root权限了

更换软件源

vim /etc/apt/sources.list

插入

deb http://mirrors.aliyun.com/debian bookworm main non-free contrib
deb-src http://mirrors.aliyun.com/debian bookworm main non-free contrib

或者

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free

更新软件包列表

apt update
点我评论
打赏本文
二维码


128

文章

14

标签

 访客统计  Update-******