Skip to content

Instantly share code, notes, and snippets.

@airtonix
Created May 8, 2025 09:27
Show Gist options
  • Save airtonix/2a4cf1fea26f82ff439690ec24c3ef79 to your computer and use it in GitHub Desktop.
Save airtonix/2a4cf1fea26f82ff439690ec24c3ef79 to your computer and use it in GitHub Desktop.

Zed Remote Devcontainers

> tree . -a
.
├── connect.sh
├── .devcontainer
│   ├── devcontainer.json
│   ├── Dockerfile
│   └── postCreate.sh
├── keys
│   ├── temp-ssh-key
│   └── temp-ssh-key.pub
└── start.sh

chmod +x ./*.sh;

find . -name "_devcontainer_*".sh -print0 | while IFS= read -r -d $'\0' file; do
  new_file="${file#*_devcontainer_}"
  mv "$file" ".devcontainer/$new_file"
done

npm i -g @devcontainers/cli

./start.sh

./connect.sh

I personally couldn't get my fedora setup to connect:

Failed to check metadata of Zed executable path for use in askpass. Please try again.

{
"name": "devcontainer CLI Demo",
"build": {
"dockerfile": "Dockerfile"
},
// 👇 Dev Container Features - https://containers.dev/implementors/features/
"features": {
"ghcr.io/devcontainers/features/sshd:1": {}
},
"postCreateCommand": ".devcontainer/postCreate.sh",
"appPort": [
// Expose SSH port for tools that need it (e.g. JetBrains)
"127.0.0.1:2222:2222"
],
"remoteUser": "vscode"
}
FROM mcr.microsoft.com/devcontainers/base:1-bookworm
#!/bin/sh
set -e
if ! type vim >/dev/null 2>&1; then
sudo apt-get update
fi
# Copy generated keys
mkdir -p $HOME/.ssh
cat /keys/temp-ssh-key.pub >$HOME/.ssh/authorized_keys
chmod 644 $HOME/.ssh/authorized_keys
chmod 700 $HOME/.ssh
#!/bin/bash
# Connect
ssh -t -i ./keys/temp-ssh-key -o "IdentitiesOnly=yes" -o NoHostAuthenticationForLocalhost=yes -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null -p 2222 vscode@localhost exec bash
#!/bin/sh
set -e
cd "$(dirname $0)"
remove_flag=""
if [ "$1" = "true" ]; then
remove_flag="--remove-existing-container"
fi
# Generate certificate
mkdir -p ./keys
rm -f ./keys/temp-ssh-key*
ssh-keygen -q -N '' -t rsa -f ./keys/temp-ssh-key
# Start container
devcontainer up $remove_flag \
--mount "type=bind,source=$(pwd)/keys,target=/keys" \
--workspace-folder ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment