簡體   English   中英

docker-compose 安裝卷上的 WSL 文件權限問題

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

我在WSL環境中使用 docker-compose。 我注意到正在運行的 docker 容器創建的一些文件顯示為 user=root 和 group=root。 如何更改 docker-compose 以在我當前的 UID 和 GID 下創建新文件?

我注意到在WSL bash shell 中,我可以在沒有 sudo 的情況下以普通用戶身份刪除 root:root 擁有的文件。 相反,正在運行的 docker 容器不能刪除文件,即使該文件不屬於 root。

這些文件位於/mnt/c/projects-new/...或 Windows 的c:\projects-new中。

/etc/wsl.conf

[network]
generateResolvConf = true

在您詢問之前,Linux 權限的元數據在/etc/fstab中定義:

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

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

貓 /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

我的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      

不確定這是否可行,但我沒有足夠的聲譽發表評論:

  • 這是我在wsl.conf中的automount部分
[automount]
enabled = true
mountfstab = true
root = /mnt/
options = metadata,uid=1000,gid=1000,umask=0022,fmask=11,case=off
  • 在選項中設置您的uidgid 如果這不起作用,下一步是將您的用戶添加到docker組:(如果您還沒有它,則必須使用sudo groupadd docker創建它)
sudo usermod -aG docker <your-user>
  • 在此之后將 docker 的所有者和組更改為您的用戶和組的可執行文件docker
sudo chown docker:<your-user> docker-compose

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM