Skip to content

Instantly share code, notes, and snippets.

@robvanoostenrijk
Last active January 3, 2025 06:54
Show Gist options
  • Save robvanoostenrijk/4f2e71add996ee5080ba11757b140ea3 to your computer and use it in GitHub Desktop.
Save robvanoostenrijk/4f2e71add996ee5080ba11757b140ea3 to your computer and use it in GitHub Desktop.
Visual Code Remote Tunnel - Docker

Visual Studio Code - Remote Tunnel

Simple example to deploy a docker container to run Visual Studio Code CLI to establish a remote tunnel to use with https://vscode.dev/

Deployment

Save both Dockerfile and docker-compose.yml in a folder. Create a sub-folder called home to persist the user data

Start with docker compose up vscode -d

Check the logs for instructions to authorize the tunnel with Github and get the tunnel URL: docker logs -f vscode

services:
vscode:
build: .
container_name: vscode
entrypoint: >
/app/code tunnel --name mytunnel
group_add:
- 102 # docker
restart: always
user: "1000:1000"
volumes:
- ./home:/home/user
- /mnt/data:/mnt/data
- /var/run/docker.sock:/var/run/docker.sock:ro
# syntax=docker/dockerfile:1
FROM alpine
RUN <<EOF
set -ex
sed -i -r 's/v\d+\.\d+/edge/g' /etc/apk/repositories
apk update
apk upgrade --no-interactive --latest
apk add --no-cache --virtual \
brotli \
ca-certificates \
curl \
docker-cli \
docker-zsh-completion \
git \
git-zsh-completion \
jq \
nodejs \
openssh \
rsync \
tar \
yq-go \
wget \
zstd \
zsh \
zopfli
curl --location --silent --output /tmp/vscode_cli.tar.gz 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64'
mkdir /app
cd /app
tar -xvf /tmp/vscode_cli.tar.gz
rm /tmp/vscode_cli.tar.gz
adduser -h /home/user -s /bin/zsh -u 1000 -D user
EOF
USER 1000:1000
ENV HOME=/home/user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment