简体   繁体   English

docker-compose 安装卷上的 WSL 文件权限问题

[英]WSL File permission problems on docker-compose mounted volumes

I'm using docker-compose in a WSL environment.我在WSL环境中使用 docker-compose。 I noticed some of the files created by the running docker container show up as user=root and group=root.我注意到正在运行的 docker 容器创建的一些文件显示为 user=root 和 group=root。 How can I change the docker-compose to create new files under my current UID and GID?如何更改 docker-compose 以在我当前的 UID 和 GID 下创建新文件?

I noticed that in the WSL bash shell I can delete files owned by root:root as a regular user without sudo.我注意到在WSL bash shell 中,我可以在没有 sudo 的情况下以普通用户身份删除 root:root 拥有的文件。 Conversely the running docker containers can't delete files, even if the file wasn't owned by root.相反,正在运行的 docker 容器不能删除文件,即使该文件不属于 root。

The files are at /mnt/c/projects-new/... or in Windows at c:\projects-new .这些文件位于/mnt/c/projects-new/...或 Windows 的c:\projects-new中。

/etc/wsl.conf /etc/wsl.conf

[network]
generateResolvConf = true

Before you ask, metadata for Linux perms is defined in /etc/fstab :在您询问之前,Linux 权限的元数据在/etc/fstab中定义:

LABEL=cloudimg-rootfs / ext4 defaults 0 0
C: /mnt/c drvfs defaults,metadata 0 0

I'm using Win 10 20H2 (OS Buidl 19042.928) WSL Version 2我正在使用Win 10 20H2 (OS Buidl 19042.928) WSL Version 2

cat /etc/*release猫 /etc/*释放

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

My docker-compose.yml file is as below:我的docker-compose.yml文件如下:

version: "3.2"
services:
  ssc-file-generator-db2-test:
    container_name: "ssc-file-generator-db2-test"
    image: ibmcom/db2:latest
    hostname: db2server
    privileged: true
    env_file: ["acceptance-run.environment"]
    ports:
      - 50100:50000
      - 55100:55000
    networks:
      - back-tier
    restart: "no"
    volumes:
      - setup-sql:/setup-sql
      - db2-shell-scripts:/var/custom
      - host-dirs:/host-dirs
      - database:/database  
networks:
  back-tier: 
    external: true
volumes:
  setup-sql:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./setup-sql  
  db2-shell-scripts:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./db2-shell-scripts
  host-dirs:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./host-dirs
  flyway_wait_bin:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./flyway/wait_bin
  flyway_conf:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./flyway/conf
  flyway_drivers:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./flyway/drivers
  flyway_sql:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./flyway/sql
  flyway_jars:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./flyway/jars
  database:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./database      

Not sure that this will work but I don't have enough reputation to comment:不确定这是否可行,但我没有足够的声誉发表评论:

  • This is my my automount section in wsl.conf这是我在wsl.conf中的automount部分
[automount]
enabled = true
mountfstab = true
root = /mnt/
options = metadata,uid=1000,gid=1000,umask=0022,fmask=11,case=off
  • Set your uid and gid in options.在选项中设置您的uidgid If this does not work the next step is to add your user to the docker group: (if you don't have it already you will have to create it with sudo groupadd docker )如果这不起作用,下一步是将您的用户添加到docker组:(如果您还没有它,则必须使用sudo groupadd docker创建它)
sudo usermod -aG docker <your-user>
  • After this change the owner and group of the docker compose executable to your user and group to docker在此之后将 docker 的所有者和组更改为您的用户和组的可执行文件docker
sudo chown docker:<your-user> docker-compose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM