问题场景:
环境:
Windows 10
Docker Desktop 4.16
项目需要构建一个all-in-one
容器,在容器内将项目所有其他容器启动。
例如postgresql
,redis
等组件
这些组件全部配置在docker-compose.yml
中
docker-compose.yml
位于all-in-one容器内
现在我们用一个命令先启动 all-in-one 容器,该容器挂载了docker.sock
用于操作docker engine
docker run -p 5888:5888 -p 80:80 -p 443:443 -it -v c:/project/etc/bp:/etc/bp -v c:/project/tmp/:/opt/tmp -v c:/project/home/project_storage:/home/project_storage -v //var/run/docker.sock:/var/run/docker.sock --name=abc debian11:v1 /bin/bash
然后我们进入到该容器内,用 docker-compose 命令启动所有其他容器
docker-compose -f docker-compose.yml up -d
启动时报错
例如启动redis 的报错
PS C:\Users\abc> docker logs -f 116
chown: .: Operation not permitted
chown: .: Operation not permitted
chown: .: Operation not permitted
chown: .: Operation not permitted
chown: .: Operation not permitted
chown: .: Operation not permitted
docker-compose.yml 部分配置如下
version: '2.4'
services:
postgresql:
container_name: postgresql
image: postgresql:latest
restart: always
healthcheck:
test: pg_isready
interval: 15s
timeout: 2s
retries: 20
start_period: 10s
environment:
POSTGRES_PASSWORD: *****
POSTGRES_USER: postgres
PGDATA: /data
volumes:
- /c/project/home/project_storage/postgresql/data:/data
postgresql 也有类似的报错
都是没有操作权限
解决方案:
PS C:\Users\abc> docker run --privileged=true -it -v /run/desktop/mnt/host/c/project/etc/bp:/etc/bp -v /run/desktop/mnt/host/c/project/tmp/:/opt/tmp -v /run/desktop/mnt/host/c/project/home/project_storage:/home/project_storage -v //var/run/docker.sock:/var/run/docker.sock --name=abc debian11:v1 /bin/bash
这样挂载后,docker-compose.yml
文件内的volume配置也要修改为
version: '2.4'
services:
postgresql:
container_name: postgresql
image: postgresql:latest
restart: always
healthcheck:
test: pg_isready
interval: 15s
timeout: 2s
retries: 20
start_period: 10s
environment:
POSTGRES_PASSWORD: *****
POSTGRES_USER: postgres
PGDATA: /data
volumes:
- /run/desktop/mnt/host/c/project/home/project_storage/postgresql/data:/data
这样postgresql,redis 等容器就能起来了,不会再报权限问题文章来源:https://www.toymoban.com/news/detail-426346.html
参考:
https://stackoverflow.com/questions/71018631/kubernetes-on-docker-for-windows-persistent-volume-with-hostpath-gives-operatio文章来源地址https://www.toymoban.com/news/detail-426346.html
到了这里,关于【云原生】解决在Windows上在docker内启动docker报Operation not permitted的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!