windows docker 执行apt-get 权限问题

今天在windows下安装的docker 部署的容器执行apt-get遇到权限问题

bash 复制代码
PS C:\Users\xiaok> docker exec -it jenkins sh
$ apt-get update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
$ sudo apt-get update
sh: 2: sudo: not found
$ su apt-get update
su: user apt-get does not exist or the user entry does not contain all the required fields
$ apk add --no-cache sudo
sh: 4: apk: not found

换一个命令执行

bash 复制代码
   docker exec -u 0 -it <jenkins_container_id> /bin/bash

由于我的容器是jenkins 所以我的执行命令是

bash 复制代码
   docker exec -u 0 -it jenkins /bin/bash
bash 复制代码
PS C:\Users\xiaok> docker exec -u 0 -it jenkins /bin/bash
root@3be2defd39e0:/# 

这个时候再去执行apt-get update就可以了

相关推荐
程序员老赵17 小时前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
lichenyang4533 天前
Docker 学习笔记(五):Docker Compose,用一个 YAML 启动前端、后端和 MongoDB
docker
lichenyang4533 天前
Docker 学习笔记(四):Dockerfile,把项目打成自己的镜像
docker·容器
lichenyang4533 天前
Docker 学习笔记(三):Docker 网络、bridge、子网和容器互通
docker·容器
lichenyang4533 天前
Docker 学习笔记(二):docker run 的参数到底在控制什么?
docker·容器
Patrick_Wilson8 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
Suroy8 天前
DockerView-Go:用 Go 写一个终端 Docker 监控工具,顺便做了个 Web 仪表盘
docker
云恒要逆袭8 天前
运行你的第一个Docker容器
后端·docker·容器
宋均浩9 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵10 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程