The purpose of this gist is to document the setup of VSCode + VPS to allow remote development in containers.
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.
This follows this VS Code remote docker host guide with some help from this VS Code containers guide.
- Spend too much time researching and comparing VPSs with little idea of what you need.
- Somewhat arbitrarily select Kamatera which seems minimal, cheap, and expandable.
- 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)
- SSH as root once the server is up
- Add a new user (per this)
- 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"
- Add the key to the local SSH Agent
ssh-add ~/.ssh/id_ed25519-remote-ssh
- 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"
- 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
- Fix
sudo: unable to resolve host dev-vps
error per this - Install docker per this
- Add the user you created to the docker group per this (so you don't have to sudo docker commands)
- Fire up VS Code, connect to the remote host, and container away...
- 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.