DEV Community

r7kamura
r7kamura

Posted on

4

GitHub CLI on devcontainer

To use the GitHub CLI (a.k.a. gh) on devcontainer, you need to pass credentials for that.

If you run gh auth login on 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 in docker-compose.yml since it is the developer's preference whether to use gh and devcontainer or not. In such case, it would be nice to add that setting to docker-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
Enter fullscreen mode Exit fullscreen mode
# .gitignore or .git/info/exclude
docker-compose.override.yml
.devcontainer/devcontainer.json
Enter fullscreen mode Exit fullscreen mode

Normally, docker-compose command will automatically merge docker-compose.override.yml into docker-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"]
}
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay