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

Win10下Docker Compose Up报错:unknown file mode ?rwxr-xr-x

问题:Docker Compose执行docker compose up -d报错failed to solve: archive/tar: unknown file mode ?rwxr-xr-x

在全新Windows 10机器上使用Docker 4.25.2版本时,执行docker compose up -d出现上述错误,但单独执行docker build --no-cache --rm=false .可成功构建镜像,无报错。

已尝试操作:

  • 执行docker system prune -a清理所有容器
  • 检查Docker设置,拉取公共容器可正常运行
  • 此前该Docker配置可正常工作,格式化机器后出现此问题

相关配置文件

docker-compose.yml

version: "3"

services:
  web:
    # the application's web service (container) will use an image based on our Dockerfile
    build: .
    # map the internal port 80 to port 8000 on the host
    ports:
      - "8000:80"
    # map the host directory to app (which allows us to see and edit files inside the container)
    volumes:
      - ".:/app:rw"
      - "./data:/data:rw"
    # the default command to run whenever the container is launched
    command: python manage.py runserver 0.0.0.0:80
    # the URL 'postgres' or 'mysql' will point to the application's db service
    networks:
      - default
    depends_on:
      - db
      - cache
      - search
    env_file: .env-local

  db:
    # Select one of the following db configurations for the database
    image: mysql:5.7
    command: --max_allowed_packet=32505856 --character-set-server=utf8 --collation-server=utf8_general_ci
    ports:
      - "3360:3306"  # allow your local dev env to connect to the db
    environment:
      MYSQL_DATABASE: "nnuh"
    volumes:
      - ".:/app:rw"
      - "./data/db:/var/lib/mysql"
    networks:
      - default

  cache:
    image: memcached:alpine

  search:
    image: elasticsearch:5.6-alpine
    volumes:
      - ./data/search/data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
    environment:
      - discovery.type=single-node

Dockerfile

FROM python:3.9
ENV PYTHONUNBUFFERED 1

# install Dependencies
RUN apt-get update && apt-get install -y \
        gcc \
        gettext \
        curl \
        --no-install-recommends && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi
解决方案

该错误源于Windows文件系统权限格式与Linux容器不兼容,可尝试以下解决办法:

  • 添加.dockerignore文件精简构建上下文
    在项目根目录创建.dockerignore,写入以下内容,排除不必要的文件(尤其是Windows特有的文件或权限异常的目录):

    .git/
    .env-local
    data/
    __pycache__/
    *.pyc
    *.pyo
    *.pyd
    .vscode/
    .idea/
    

    减少构建时打包的文件数量,避免权限冲突。

  • 带缓存禁用参数执行Docker Compose构建
    直接执行命令时添加--no-cache参数:

    docker compose up -d --build --no-cache
    

    或者修改docker-compose.yml中web服务的build配置:

    build:
      context: .
      dockerfile: Dockerfile
      args:
        - BUILDKIT_INLINE_CACHE=0
    
  • 检查Docker文件共享与本地文件夹权限

    1. 打开Docker Desktop,进入资源 > 文件共享,确保项目所在磁盘已勾选共享。
    2. 右键项目文件夹,选择属性 > 安全,确认当前用户拥有完全控制权限,且文件夹未开启加密或压缩。
  • 临时切换为Windows容器模式(仅适用于Windows依赖项目)
    如果上述方法无效,可尝试切换Docker的容器类型为Windows容器,但此操作会影响Linux容器运行,需根据项目需求选择。

内容的提问来源于stack exchange,提问作者Israa Salameh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 21:28:41