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

VSCode/WSL2重构开发容器时出现Too many open files错误

解决Dev Container添加MySQL特性时的「Too many open files」错误

方案1:改用官方MySQL Dev Container特性(推荐)

你当前使用的ghcr.io/devcontainers-contrib/features/mysql-homebrew是非官方维护的Homebrew版本,在容器环境中容易触发文件句柄限制问题。建议替换为微软官方维护的MySQL特性,适配性更稳定:

修改你的devcontainer.json:

{
    "name": "Node.js & TypeScript",
    "image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
    "features": {
        "mcr.microsoft.com/devcontainers/features/mysql:1": {
            "mysqlVersion": "8.0",
            "password": "root" // 可自定义密码
        }
    }
}

修改后重新执行「Dev Containers: Rebuild and reopen in container」即可完成安装。

方案2:调整容器的文件句柄限制(针对坚持使用Homebrew版本的情况)

WSL主机的文件句柄限制不会直接传递给容器,需要在容器启动时单独设置:

在devcontainer.json中添加runArgs参数,指定容器的最大打开文件数:

{
    "name": "Node.js & TypeScript",
    "image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
    "runArgs": [
        "--ulimit", "nofile=65536:65536"
    ],
    "features": {"ghcr.io/devcontainers-contrib/features/mysql-homebrew:1":{}}
}

这个参数会在容器启动时将软限制和硬限制都设置为65536,满足MySQL安装时的文件句柄需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 11:22:45