Windows环境下Cookiecutter Django初始docker-compose构建失败求助
问题分析
报错exit code: 100是apt-get update或安装包时网络访问失败导致的,大概率是默认软件源访问不畅,或是Windows下Docker的网络配置有问题。
具体解决方案
1. 替换国内软件源
找到项目中对应服务的Dockerfile(一般是web服务的Dockerfile),把apt-get update && apt-get install...那段替换成带国内源的命令:
Debian镜像用阿里云源:
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \ sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \ apt-get update && apt-get install --no-install-recommends -y build-essential libpq-dev
Ubuntu镜像用清华源:
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \ sed -i 's/security.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \ apt-get update && apt-get install --no-install-recommends -y build-essential libpq-dev
2. 调整Docker网络配置
- 打开Docker Desktop,进入「Settings > Resources > Network」
- 试试切换WSL2/Hyper-V模式(勾掉或勾选「Use the WSL 2 based engine」)
- 重启Docker后重新执行构建:
docker-compose -f local.yml build
3. 清理Docker缓存再构建
缓存的旧源信息可能拖后腿,先清缓存再重新构建:
docker system prune -af docker-compose -f local.yml build --no-cache
4. 配置代理(如果你的机器用代理上网)
- 在Docker Desktop的「Settings > Resources > Proxies」里手动填入代理地址和端口
- 或者在
local.yml的服务配置里加代理环境变量:
services: web: environment: - HTTP_PROXY=http://你的代理地址:端口 - HTTPS_PROXY=http://你的代理地址:端口 - NO_PROXY=localhost,127.0.0.1
内容的提问来源于stack exchange,提问作者jodan01
相关产品推荐
相关产品推荐

