[BUG] <title>在Windows上按照教程中的方式启动docker,最终 mysql-container-local 这个容器会报错。
Author: xzgcCreated Sep 25, 2025Updated Aug 16, 2026
是否已有关于该错误的issue或讨论? | Is there an existing issue / discussion for this?
- 我已经搜索过已有的issues和讨论 | I have searched the existing issues / discussions
该问题是否在FAQ中有解答? | Is there an existing answer for this in FAQ?
- 我已经搜索过FAQ | I have searched FAQ
当前行为 | Current Behavior
No response
期望行为 | Expected Behavior
解决方案:在项目根路径下 使用node运行 我写的这个js脚本内容即可解决。
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
/**
* 修复文件换行符,将 CRLF (\r\n) 转换为 LF (\n)
* @param {string} filePath - 要修复的文件路径
*/
function fixLineEndings(filePath) {
try {
console.log(`正在处理文件: ${filePath}`);
// 检查文件是否存在
if (!fs.existsSync(filePath)) {
console.error(`错误: 文件不存在 - ${filePath}`);
return false;
}
// 读取文件内容
const content = fs.readFileSync(filePath, 'utf8');
// 检查是否包含 CRLF
const hasCRLF = content.includes('\r\n');
if (!hasCRLF) {
console.log(`文件已经是 Unix 格式 (LF),无需转换: ${filePath}`);
return true;
}
// 统计 CRLF 数量
const crlfCount = (content.match(/\r\n/g) || []).length;
console.log(`发现 ${crlfCount} 个 CRLF 换行符`);
// 转换换行符
const fixedContent = content.replace(/\r\n/g, '\n');
// 写回文件
fs.writeFileSync(filePath, fixedContent, 'utf8');
console.log(`✅ 成功转换文件: ${filePath}`);
console.log(` 转换了 ${crlfCount} 个换行符`);
// 验证转换结果
const verifyContent = fs.readFileSync(filePath, 'utf8');
const remainingCRLF = (verifyContent.match(/\r\n/g) || []).length;
if (remainingCRLF === 0) {
console.log(`✅ 验证通过: 文件已完全转换为 Unix 格式`);
return true;
} else {
console.error(`❌ 验证失败: 仍有 ${remainingCRLF} 个 CRLF 换行符`);
return false;
}
} catch (error) {
console.error(`处理文件时出错: ${filePath}`);
console.error(`错误信息: ${error.message}`);
return false;
}
}
/**
* 批量处理多个文件
* @param {string[]} filePaths - 文件路径数组
*/
function fixMultipleFiles(filePaths) {
let successCount = 0;
let totalCount = filePaths.length;
console.log(`\n开始批量处理 ${totalCount} 个文件...\n`);
for (const filePath of filePaths) {
if (fixLineEndings(filePath)) {
successCount++;
}
console.log(''); // 空行分隔
}
console.log(`批量处理完成: ${successCount}/${totalCount} 个文件成功转换`);
if (successCount === totalCount) {
console.log(' 所有文件转换成功!');
return true;
} else {
console.log('⚠️ 部分文件转换失败,请检查上述错误信息');
return false;
}
}
// 主函数
function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.log('用法:');
console.log(' node fix-line-endings.js <文件路径1> [文件路径2] ...');
console.log(' node fix-line-endings.js scripts/entrypoint.sh');
console.log(' node fix-line-endings.js scripts/*.sh');
console.log('');
console.log('功能: 将文件的换行符从 Windows 格式 (CRLF) 转换为 Unix 格式 (LF)');
process.exit(1);
}
// 处理通配符
let filePaths = [];
for (const arg of args) {
if (arg.includes('*')) {
// 简单通配符处理
const dir = path.dirname(arg);
const pattern = path.basename(arg);
try {
const files = fs.readdirSync(dir);
const matchedFiles = files.filter(file => {
const regex = new RegExp(pattern.replace(/\*/g, '.*'));
return regex.test(file);
});
filePaths.push(...matchedFiles.map(file => path.join(dir, file)));
} catch (error) {
console.error(`无法读取目录: ${dir}`);
}
} else {
filePaths.push(arg);
}
}
// 去重
filePaths = [...new Set(filePaths)];
if (filePaths.length === 0) {
console.error('没有找到要处理的文件');
process.exit(1);
}
const success = fixMultipleFiles(filePaths);
process.exit(success ? 0 : 1);
}
// 如果直接运行此脚本
if (require.main === module) {
main();
}
module.exports = { fixLineEndings, fixMultipleFiles };
运行环境 | Environment
- OS:
- NVIDIA Driver:
- CUDA:
- Docker Compose:
- NVIDIA GPU Memory:QAnything日志 | QAnything logs
No response
复现方法 | Steps To Reproduce
No response
备注 | Anything else?
No response
Source: netease-youdao/QAnything