How to Use GitHub Copilot Inside a Devcontainer
🔍 WiseChecker

How to Use GitHub Copilot Inside a Devcontainer

GitHub Copilot provides AI-powered code suggestions directly in your editor. When you work inside a devcontainer, your development environment runs in an isolated Docker container. This setup can block Copilot from connecting to the GitHub API or accessing your local authentication. Without the correct configuration, Copilot will show no suggestions or return an error about missing authentication. This article explains how to enable GitHub Copilot inside a devcontainer using the Dev Containers extension and the proper settings.

Key Takeaways: Enable Copilot in Devcontainer

  • Dev Containers extension > Reopen in Container: Opens your project inside a Docker container with full editor integration.
  • .devcontainer/devcontainer.json > “extensions”: Add “GitHub.copilot” and “GitHub.copilot-chat” to install Copilot inside the container.
  • VS Code settings.json > “github.copilot.enable”: Set to {"": true} to force Copilot activation in all languages within the container.

What GitHub Copilot Needs Inside a Devcontainer

A devcontainer runs your code in a lightweight Docker container. The container has its own filesystem, extensions, and settings. By default, the container does not have access to your host machine’s VS Code extensions or authentication tokens. GitHub Copilot requires two things to function inside a devcontainer: the Copilot extension must be installed in the container, and the container must be able to authenticate with GitHub using your existing token.

The Dev Containers extension for VS Code handles the setup. When you open a folder with a .devcontainer configuration, VS Code builds the container and mounts your workspace. Extensions listed in devcontainer.json are installed automatically. Copilot uses the GitHub authentication that VS Code already has on the host. The container can forward this authentication through a feature called Git Credential Manager or by mounting the host’s .config folder.

Prerequisites

Before you start, confirm these items are ready on your host machine:

  • VS Code with the Dev Containers extension installed
  • Docker Desktop or Docker Engine running
  • GitHub Copilot subscription active and signed in on the host VS Code
  • GitHub CLI or Git Credential Manager configured on the host

Steps to Enable GitHub Copilot in a Devcontainer

Follow these steps to configure your devcontainer so Copilot works inside the container environment.

  1. Create or open your devcontainer configuration
    In your project root, create a folder named .devcontainer. Inside it, create a file named devcontainer.json. If your project already has one, open that file. This JSON file tells VS Code how to build and configure the container.
  2. Add the Copilot extensions to the extensions list
    In devcontainer.json, locate or add the "extensions" array. Insert these two entries: "GitHub.copilot" and "GitHub.copilot-chat". The file should look like this:
    "extensions": ["GitHub.copilot", "GitHub.copilot-chat"]
    This ensures both the Copilot code completion and the Copilot Chat interface are installed inside the container.
  3. Forward authentication to the container
    Copilot needs your GitHub authentication token. The easiest method is to mount the host’s .config folder that contains the GitHub CLI token. Add this to devcontainer.json:
    "mounts": ["source=${env:HOME}${env:USERPROFILE}/.config,target=/home/vscode/.config,type=bind"]
    On Windows, adjust the path to C:\Users\YourUsername\.config. Alternatively, use the gh auth login command inside the container after it starts.
  4. Enable Copilot in the container settings
    Some containers override VS Code settings. Add a "settings" object in devcontainer.json to force Copilot on:
    "settings": { "github.copilot.enable": { "
    ": true } }
    This tells Copilot to activate for all file types inside the container.
  5. Rebuild and reopen the container
    Press Ctrl+Shift+P to open the Command Palette. Type Dev Containers: Rebuild and Reopen in Container and select it. VS Code will rebuild the container with the new configuration. After the container starts, wait for the extensions to install. You should see the Copilot icon in the status bar.
  6. Verify Copilot is working
    Open a code file inside the container. Start typing a function or comment. Copilot should show gray inline suggestions. Press Tab to accept a suggestion. If no suggestions appear, check the Copilot status icon in the bottom-right corner. It should show a green checkmark indicating Copilot is active.

Common Issues When Using Copilot in a Devcontainer

Copilot shows “Not Authenticated” error

This error means the container cannot reach GitHub to verify your subscription. The root cause is that the authentication token from the host is not forwarded. Recheck the mounts configuration in devcontainer.json. Ensure the path to .config is correct for your operating system. On Linux and macOS, the path is ${env:HOME}/.config. On Windows, use ${env:USERPROFILE}/.config. After fixing the path, rebuild the container. If the issue persists, manually authenticate inside the container by running gh auth login in the integrated terminal.

Copilot extension is missing after container rebuild

If the Copilot extension does not appear after rebuilding, the extensions array in devcontainer.json might be misspelled or placed incorrectly. Verify that the array is at the top level of the JSON object. It must not be nested inside "settings" or "build". Also confirm the extension IDs are exactly "GitHub.copilot" and "GitHub.copilot-chat". A common typo is writing "github.copilot" with a lowercase ‘g’. Extension IDs are case-sensitive.

Copilot suggestions are slow or delayed inside the container

Network latency between the container and the GitHub API can cause slow suggestions. The container must have internet access. If your Docker network uses a proxy or VPN, Copilot may time out. Check the container’s network settings in Docker Desktop. Ensure the container can reach api.github.com on port 443. You can test this by running curl https://api.github.com inside the container’s terminal. If the request fails, adjust your Docker network configuration or disable the proxy for the container.

Devcontainer Copilot Setup: Local vs Remote Container Comparison

Item Local Devcontainer Remote Devcontainer via SSH
Description Container runs on your local machine using Docker Container runs on a remote server accessed via SSH
Authentication method Mount host .config folder or use gh auth login Must forward SSH agent and authenticate inside the remote container
Extension installation Automatic via devcontainer.json extensions list Automatic via devcontainer.json, but requires SSH agent forwarding
Network latency Low latency to GitHub API Higher latency due to remote hop
Recommended for Local development with full control Team environments or cloud-based development

After you complete the configuration, Copilot works the same way inside the container as it does on your host. You can use inline suggestions, Copilot Chat, and the Copilot panel without interruption. For advanced setups, consider adding the "forwardPorts" setting in devcontainer.json if your container hosts a web service that Copilot needs to analyze. Also review the "remoteEnv" setting to pass environment variables like GITHUB_TOKEN if your workflow requires it.