Skip to content

Instantly share code, notes, and snippets.

@natecostello
Last active August 18, 2022 03:59
Show Gist options
  • Save natecostello/1130784354d3bddda03dfc2bb58e4501 to your computer and use it in GitHub Desktop.
Save natecostello/1130784354d3bddda03dfc2bb58e4501 to your computer and use it in GitHub Desktop.
Developing with VSCode in containers on a VPS

Purpose

The purpose of this gist is to document the setup of VSCode + VPS to allow remote development in containers.

Motivation

The reason for developing in this way is to assuage my fear of purchasing a new Mac with only 16GB of RAM that will replace my several-year-old Mac that has only 16GB of RAM. The new fancy RAM is supposed to be enough except for people that run a lot of Docker containers on Macs which uses a virtual machine, which ties up a fixed amount of RAM. With this method, the Mac runs no containers, thus no virtual machine, and thus no memory issue.

Steps

This follows this VS Code remote docker host guide with some help from this VS Code containers guide.

  1. Spend too much time researching and comparing VPSs with little idea of what you need.
  2. Somewhat arbitrarily select Kamatera which seems minimal, cheap, and expandable.
  3. Create a new server:
  • Located in Texas (since we bounce between coasts presently)
  • Running Ubuntu 22.04 LTS "optimized_updated" (meets requirements, not sure what that last bit is)
  • Of type "Availability" (cheap and sufficient)
  • With 1 CPU (2 is recommended)
  • With 2 GB RAM (recommended)
  • With 20 GB Storage (Maximum at minimum price)
  • With "Simple Mode" Networking - Public Internet Network
  • Named dev-vps
  • A strong password
  • Monthly Billing $6 (Billing monthly includes 5TB of data)
  1. SSH as root once the server is up
  2. Add a new user (per this)
  3. On the local machine generate a dedicated SSH Key (steps 6, 7, 8, and 9 are per this and this)
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519-remote-ssh -C "name@gmail.com"
  1. Add the key to the local SSH Agent
ssh-add ~/.ssh/id_ed25519-remote-ssh
  1. Copy your local public key to the SSH host (dev-vps)
export USER_AT_HOST="your-user-name-on-host@hostname"
export PUBKEYPATH="$HOME/.ssh/id_ed25519-remote-ssh.pub"
ssh-copy-id -i "$PUBKEYPATH" "$USER_AT_HOST"
  1. Add a new host entry to the local SSH config file (~/.ssh/config) (note: the last line forward the agent so the remote host can use your credentials for things like git)
Host name-of-ssh-host-here
   User your-user-name-on-host
   HostName host-fqdn-or-ip-goes-here
   IdentityFile ~/.ssh/id_ed25519-remote-ssh
   ForwardAgent yes
  1. Fix sudo: unable to resolve host dev-vps error per this
  2. Install docker per this
  3. Add the user you created to the docker group per this (so you don't have to sudo docker commands)
  4. Fire up VS Code, connect to the remote host, and container away...

Afterward

  • I went ahead and beefed up the server, super easy, all it required was a restart. It now has 6A CPUs and 4GB RAM with hourly billing. I'm using two shell scripts with MacOS shortcuts to turn on and off the server. It costs ~$5.80 per month off and about 3 cents per hour when on.
  • I'm no longer using a dedicated SSH key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment