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

相关推荐
梦想的颜色3 小时前
【Docker原理】Docker 容器一文打尽:生命周期、环境管控、迁移备份、日志进程排查、垃圾清理
运维·docker·容器·容器生命周期·容器日志排查·容器迁移备份·容器进程管理
donoot5 小时前
Linux系统下图书馆级电子书全自动标准化分类整理完整实施方案
大数据·linux·运维·电子书管理
ITKEY_6 小时前
macOS brew 安装的nginx 文件在哪里?
运维·nginx·macos
Elastic 中国社区官方博客6 小时前
如何比较两个 Elasticsearch 索引并找出缺失的文档
大数据·运维·数据库·elasticsearch·搜索引擎
万里侯6 小时前
GitOps 漂移检测:集群里改了配置,Git 还以为一切正常
微服务·容器·k8s
Tim_Van7 小时前
在 CentOS 7 中安装 Chromium 的完整步骤
linux·运维·chrome·centos
孫治AllenSun8 小时前
【Nginx】配置参数和使用案例
运维·nginx
啵啵鱼爱吃小猫咪9 小时前
Ubuntu 20.04 + ROS Noetic 源码安装 libfranka 0.8.0 和 franka_ros 0.8.0 完整教程
linux·运维·ubuntu
Piko61410 小时前
锐捷 VSU 虚拟化堆叠配置
运维·网络·笔记
ljs64827395110 小时前
Linux运维实操:vi编辑器永久配置静态IP(CentOS系列)
linux·运维·编辑器