Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Initial setup of a VS Code devcontainer for Rails; see
// For format details, see For config options, see the README at:
"name": "Yet Another To-do App",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a Ruby version: 2, 2.7, 2.6, 2.5
"VARIANT": "2.5",
"NODE_VERSION": "lts/*"
// Set *default* container specific settings.json values on container create.
"settings": {
"": "/bin/bash"
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bin/setup",
// Comment out connect as root instead. More info:
"remoteUser": "vscode"
# [Choice] Ruby version: 2, 2.7, 2.6, 2.5
RUN su vscode -c "source /usr/local/share/nvm/ && nvm install ${NODE_VERSION} 2>&1"
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# [Optional] Uncomment this line to install additional gems.
# RUN gem install <your-gem-names-here>
# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/ && npm install -g <your-package-here>" 2>&1
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
puts "\n== Copying sample files =="
unless File.exist?('.env')
cp '.env.sample', '.env'
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
# puts "\n== Preparing database =="
# system! 'bin/rails db:setup'
# puts "\n== Removing old logs and tempfiles =="
# system! 'bin/rails log:clear tmp:clear'
# puts "\n== Restarting application server =="
# system! 'bin/rails restart'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment