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

使用Kamal部署Rails应用失败:Docker登录报错退出码256

解决Kamal部署Rails应用时Docker登录失败的问题

错误信息

ERROR (SSHKit::Command::Failed): docker exit status: 256
docker stdout: Nothing written
docker stderr: WARNING! Using --password via the CLI is insecure. Use --password-stdin.
<3>WSL (170175) ERROR: UtilAcceptVsock:250: accept4 failed 110
Error saving credentials: error storing credentials - err: exit status 1, out:

环境详情

  • Rails版本:8.0
  • Ruby版本:3.3.3
  • Kamal版本:2.3.0
  • 服务器:Ubuntu系统的Contabo VPS
  • 本地机器:Windows 11 + WSL2 + Docker Desktop

解决方案

1. 禁用WSL2中的Docker凭证存储

WSL2环境下Docker凭证存储易出现兼容性问题,直接禁用:
在WSL终端执行:

echo "{ \"credsStore\": \"\" }" > ~/.docker/config.json

或手动编辑~/.docker/config.json,删除/清空credsStore字段,让Docker使用明文存储凭证(仅用于部署场景,注意服务器端安全)。

2. 调整Kamal配置,使用标准输入传递密码

修改deploy.yml的registry配置,添加password_stdin: true,强制Kamal用标准输入传递密码,避免CLI传参的安全警告和存储问题:

registry:
  username: ibunhabibu
  password:
    - KAMAL_REGISTRY_PASSWORD
  password_stdin: true

3. 验证WSL2与Docker Desktop的集成状态

确保WSL2和Docker Desktop连接正常:

  • 打开Docker Desktop设置,进入Resources > WSL Integration
  • 启用当前使用的WSL发行版(如Ubuntu)
  • 执行wsl --shutdown重启WSL,再重新打开终端

4. 手动测试服务器端Docker登录

登录目标VPS服务器,手动执行登录命令验证凭证有效性:

echo "$KAMAL_REGISTRY_PASSWORD" | docker login -u ibunhabibu --password-stdin

若登录失败,检查Docker PAT权限或凭证正确性。

5. 检查Secrets文件变量引用

确认.kamal/secrets中的变量引用格式正确,无多余引号或语法错误:

# Grab the registry password from ENV
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
GOOGLE_API=$GOOGLE_API
PIXABAY=$PIXABAY
OPEN_WEATHER=$OPEN_WEATHER
POSTGRES_PASSWORD=$POSTGRES_PASSWORD
POSTGRES_USER=$POSTGRES_USER

# Improve security by using a password manager. Never check config/master.key into git!
RAILS_MASTER_KEY=$(cat config/master.key)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 02:49:55