问题:默认通过docker run命令或者docker-compose启动的docker容器,通过Linux命令行docker exec进入容器是普通用户权限,不支持sudo和su切换root用户操作,导致在容器中安装软件无法进行。
解决:修改docker容器启动的默认用户权限,在启动命令添加privileged参数。(以Jenkins容器化安装为例)。
1、原始docker-compose脚本如下:
web:
image: 'jenkinsci/blueocean:1.22.0'
restart: always
container_name: jenkins
ports:
- '8090:8080'
- '50000:50000'
volumes:
- '/data/jenkins/data:/var/jenkins_home'
- '/var/run/docker.sock:/var/run/docker.sock '
2、添加privileged参数后脚本如下:
web:
image: 'jenkinsci/blueocean:1.22.0'
privileged: true
user: root
restart: always
container_name: jenkins
hostname: '10.220.96.202'
ports:
- '8090:8080'
- '50000:50000'
volumes:
- '/data/jenkins/data:/var/jenkins_home'
- '/var/run/docker.sock:/var/run/docker.sock '