You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL2环境下Docker Compose执行mkdir时权限拒绝错误求助

问题描述

在Windows系统使用WSL2后端的Docker执行docker-compose up -d时,出现权限错误:

[+] Running 0/0
 - Container gekko-redis-1  Creating                                                                                                                                                                                                  0.0s 
Error response from daemon: mkdir C:\Users\userName\Desktop\Appsome_Repos\gekko\volumes: Access is denied.

怀疑是WSL2权限设置问题,相关配置文件如下:

Dockerfile

FROM node:8

ENV HOST localhost
ENV PORT 3000

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install GYP dependencies globally, will be used to code build other dependencies
RUN npm install -g --production node-gyp && \
    npm cache clean --force

# Install Gekko dependencies
COPY package.json .
RUN npm install --production && \
    npm install --production redis@0.10.0 talib@1.0.2 tulind@0.8.7 pg && \
    npm cache clean --force

# Install Gekko Broker dependencies
WORKDIR exchange
COPY exchange/package.json .
RUN npm install --production && \
    npm cache clean --force
WORKDIR ../

# Bundle app source
COPY . /usr/src/app

EXPOSE 3000
RUN chmod +x /usr/src/app/docker-entrypoint.sh
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]

CMD ["--config", "config.js", "--ui"]

docker-compose.yml

version: '3'
services:
  gekko:
    build: ./
    volumes:
      - ./volumes/gekko/history:/usr/src/app/history
      - ./config.js:/usr/src/app/config.js
    links:
      - redis
#      - postgresql
    environment:
     - HOST
     - PORT
     - USE_SSL
    ports: # you can comment this out when using the nginx frontend
      - "${PORT}:${PORT}"
## optionally set nginx vars if you wish to frontend it with nginx
#    environment:
#     - VIRTUAL_HOST=gekko
#     - PORT=3000
#     - DOMAIN=gekko

  redis:
    image: redis:latest
    volumes:
      - ./volumes/redis:/data
## optionally uncomment if you wish to use nginx as a frontend
#  nginx:
#    restart: always
#    image: jwilder/nginx-proxy
#    ports:
#     - "80:80"
#    volumes:
#     - /var/run/docker.sock:/tmp/docker.sock:ro
## optionally uncomment if you wish to use postgresql as a db
#  postgresql:
#    restart: always
#    image: postgres:9.6-alpine
#    ports:
#      - 5432:5432
#    volumes:
#      - ./_postgresql:/var/lib/postgresql/data:rw
#    environment:
#      POSTGRES_DB: gekko
#      POSTGRES_USER: username
#      POSTGRES_PASSWORD: password
解决思路
  • 手动创建目录并调整权限
    在Windows文件资源管理器中找到C:\Users\userName\Desktop\Appsome_Repos\gekko,手动创建volumes目录。右键目录→属性→安全→编辑,给当前用户添加完全控制权限;同时在WSL2终端进入对应路径(/mnt/c/Users/userName/Desktop/Appsome_Repos/gekko),执行chmod -R 777 ./volumes调整WSL侧权限。

  • 使用WSL原生路径执行命令
    打开WSL2终端,切换到项目的WSL路径(cd /mnt/c/Users/userName/Desktop/Appsome_Repos/gekko),再执行docker-compose up -d,避免Windows终端的路径解析和权限冲突。

  • 检查Docker的WSL集成设置
    打开Docker Desktop→设置→Resources→WSL Integration,确保对应WSL发行版(如Ubuntu)已开启集成,勾选"Enable integration with my default WSL distro",重启Docker后重试。

  • 调整WSL挂载权限配置
    在WSL2中创建或编辑/etc/wsl.conf文件,添加以下内容:

    [automount]
    options = "metadata,umask=0022"
    

    保存后在Windows终端执行wsl --shutdown关闭WSL,重启后挂载的Windows目录权限会更宽松。

  • 以管理员身份运行Docker Desktop
    右键Docker Desktop图标选择"以管理员身份运行",再执行docker-compose up -d,规避系统权限限制。

内容的提问来源于stack exchange,提问作者Patryk Janik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:25:21