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

在Rails Dev Container中安装Gem时遇权限错误求助

Rails开发容器中Gemfile.lock写入权限错误解决

问题场景

创建基于MySQL的全新Rails项目,操作流程:

  • 安装rails-new工具
  • 执行命令:rails-new project --devcontainer --database=mysql
  • 在VS Code中启动开发容器时,触发如下错误:
Running the postCreateCommand from devcontainer.json...

[16194 ms] Start: Run in container: /bin/sh -c bin/setup --skip-server
== Installing dependencies ==
The following gems are missing
 * rails (8.0.1)
 * propshaft (1.1.0)
 * mysql2 (0.5.6)
 * puma (6.6.0)
.....
 * unicode-emoji (4.0.4)
 * crass (1.0.6)
 * stringio (3.1.5)
Install missing gems with `bundle install`
Fetching gem metadata from https://rubygems.org/.........
Fetching benchmark 0.4.0
Fetching mini_mime 1.1.5
Fetching concurrent-ruby 1.3.5
....
Installing stimulus-rails 1.3.4
Installing thruster 0.1.11 (x86_64-linux)
Installing turbo-rails 2.0.13
Installing web-console 4.2.1
There was an error while trying to write to `/workspaces/Project/Gemfile.lock`. It is likely that you need to grant write permissions for that path.
bin/setup:7:in 'Kernel#system': Command failed with exit 23: bundle (RuntimeError)
        from bin/setup:7:in 'Object#system!'
        from bin/setup:16:in 'block in <main>'
        from /home/vscode/.rbenv/versions/3.4.2/lib/ruby/3.4.0/fileutils.rb:241:in 'Dir.chdir'
        from /home/vscode/.rbenv/versions/3.4.2/lib/ruby/3.4.0/fileutils.rb:241:in 'FileUtils#cd'
        from bin/setup:10:in '<main>'

What's next:
    Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 01b40e9210a835134bb1d565ce5c228206498e07dc46baabfb5fa80288f372a2
    Learn more at https://docs.docker.com/go/debug-cli/
[79998 ms] postCreateCommand from devcontainer.json failed with exit code 1. Skipping any further user-provided commands.
Done. Press any key to close the terminal.

解决方法

  1. 进入VS Code中开发容器的终端窗口
  2. 修正项目目录权限,将所有权切换给容器内的vscode用户:
    sudo chown -R vscode:vscode /workspaces/Project
    
  3. 手动执行gem依赖安装:
    bundle install
    
  4. 重新运行项目初始化脚本:
    bin/setup --skip-server
    

说明

该问题核心是容器内的vscode用户没有项目目录的写入权限,修正权限后即可正常完成依赖安装和项目初始化。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 03:05:53