Docker 中使用超级用户

在docker中安装keytool产生的问题:

bash 复制代码
sudo apt-get install openjdk-8-jre-headless
bash: sudo: command not found
elasticsearch@d989639e3cb4:~/config/certs$ apt-get install openjdk-8-jre-headless
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?
elasticsearch@d989639e3cb4:~/config/certs$ sudo apt-get install openjdk-8-jre-headless
bash: sudo: command not found
elasticsearch@d989639e3cb4:~/config/certs$ su
Password: 
su: Authentication failure
elasticsearch@d989639e3cb4:~/config/certs$ su
Password: 
su: Authentication failure
elasticsearch@d989639e3cb4:~/config/certs$ apt-get update && apt-get install -y openjdk-8-jre-headless
Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
elasticsearch@d989639e3cb4:~/config/certs$ exit

docker exec -u 0 -it <容器名称或ID> /bin/bash

例如:

docker exec -u 0 -it d989639e3cb4 /bin/bash

然后直接使用apt,不需要加sudo

apt-get update && apt-get install -y openjdk-8-jre-headless

相关推荐
程序猿阿伟1 小时前
随着云计算和容器技术的广泛应用,如何在这些环境中有效地运用 Shell 进行自动化部署和管理?
运维·自动化·云计算
Roc-xb2 小时前
Failed to get D-Bus connection: Operation not permitted
docker·wsl·centos7
Tassel_YUE3 小时前
iptables配置实现NAT(随手记)
linux·运维·服务器·网络·iptables
five-five3 小时前
一文全解Nginx
运维·nginx
IT利刃出鞘4 小时前
SecureCRT--使用sftp上传和下载文件
linux·运维·服务器
WolvenSec6 小时前
网络基础:EIGRP
运维·网络·安全·智能路由器
踩着阴暗的自己向上爬7 小时前
Day05-04-持续集成总结
linux·运维·ci/cd
TiDB_PingCAP8 小时前
国产化新标杆:TiDB 助力广发银行新一代总账系统投产上线
运维·数据库·开源·tidb
qyhua8 小时前
Linux内网端口转公网端口映射
linux·运维·服务器
coisini.cn9 小时前
基于CentOS Stream 9平台搭建MinIO以及开机自启
运维·minio·centos stream 9