Docker 中使用超级用户

2024-01-08 18:40:31

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

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

文章来源:https://blog.csdn.net/ckq707718837/article/details/135462773
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。