Goal: create a docker image for a vscode
dev-container.
Context: Despite the ton of resources for such a topic available on the internet, I am experiencing troubles to figure out how to make users safely push to github.com
from a vscode
dev-container.
The host is Windows (latest), the container’s OS is Ubuntu Jammy.
The key idea is to create a dev-container that is just as simple to use as WSL
.
What I tried so far (perhaps not in the good way):
- playing with
ssh-agent
- playing with
gh auth login
- playing with
git credential manager
Ideally, I’d rather not copy the ssh
keys into the container.
.devcontainer/devcontainer.json
:
{
"name": "devcontainer",
"dockerComposeFile": "./docker-compose.yaml",
"service": "dev_toolchain",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"overrideCommand": true,
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/sshd:1": {}
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } },
"remote.SSH.showLoginTerminal": true
},
"extensions": [
// some extensions
]
},
"postCreateCommand": {
"git-safe-dir-workspace": "git config --global --add safe.directory /workspace"
}
}
}
docker-compose.yaml
:
version: '3.8'
services:
dev_toolchain:
environment:
- SSH_AUTH_SOCK=/ssh-agent
build:
context: .
dockerfile: ./Dockerfile
args:
BASE_IMAGE: 'ubuntu:jammy'
ssh: # requires ssh-agent service running on host
- default
ports:
- "2222:22"
volumes:
- ..:/workspace
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
And the Dockerfile
installs various development tools.
Thanks for you time and help !
If some informations are missing, just ask me and I’ll update this post.