DevContainer/How To/Get Github Command Line Inside Dev Container
- GitHub CLI on devcontainer - DEV Community - how to get GitHub/CLI in a DevContainer
- To use the GitHub CLI (a.k.a.
gh) on devcontainer, you need to pass credentials for that.
If you rungh auth loginon the host side, the credentials will be stored at~/.config/gh/hosts.yml, so mounting it on the container side will work.
Maybe it can be difficult to include this setting indocker-compose.ymlsince it is the developer's preference whether to useghand devcontainer or not. In such case, it would be nice to add that setting todocker-compose.override.yml, and ignore these files from Git.
# docker-compose.override.yml services: rails: volumes: - ~/.config/gh/hosts.yml:/root/.config/gh/hosts.yml# .gitignore or .git/info/exclude docker-compose.override.yml .devcontainer/devcontainer.json
Normally,docker-composecommand will automatically mergedocker-compose.override.ymlintodocker-compose.yml, but in this case you need to specify it explicitly as follows:
# .devcontainer/devcontainer.json { "name": "Rails", "dockerComposeFile": [ "../docker-compose.yml", "../docker-compose.override.yml" ], "service": "rails", "workspaceFolder": "/workspace", "runServices": ["rails"] }
- To use the GitHub CLI (a.k.a.