Skip to content

Latest commit

 

History

History
65 lines (41 loc) · 2.74 KB

File metadata and controls

65 lines (41 loc) · 2.74 KB

Step 2: Use a custom image in your codespace

The didn't specify any configuration for the codespace we just created, so GitHub used a default Docker image. While this is very useful, it won't be consistent and it doesn't version lock our runtime environment. Specifying the configuration is important to keep the development environment repeatable.

Let's do that now by providing a specific docker container image.

How to configure a Codespace?

Configuration is provided directly in the repository via the .devcontainer/devcontainer.json. You can even add multiple configurations!

Let's create this file and set a few of the most common settings. For other options like setting configuring VS Code, forwarding ports, and running lifecycle scripts, see the Codespaces documentation on GitHub.

⌨️ Activity: Customize the codespace

  1. Ensure you are in the VS Code Codespace.

  2. Use the VS Code file explorer to create the configuration file.

    .devcontainer/devcontainer.json

    Alternately, run the below terminal command to create it.

    mkdir -p .devcontainer
    touch .devcontainer/devcontainer.json
  3. Open the .devcontainer/devcontainer.json file and add the following content.

    {
      "name": "Python 3.10",
      "image": "mcr.microsoft.com/vscode/devcontainers/python:3.10"
    }

    💡 Tip: The name is optional but it will help identify the configuration when creating a codespace on GitHub, if there are multiple options.

  4. After saving, VS Code likely popped up a notification that it detected a configuration change. You can Accept that option to rebuild the development container or manually use the Command Palette (CTRL+Shift+P) and run the command Codespaces: Rebuild Container. Select the Rebuild option. A full build is not necessary.

    rebuild codespace command
  5. Wait a few minutes for the Codespace to rebuild and VS Code to reconnect.

  6. Expand the lower panel and select the TERMINAL tab.

  7. Paste the following command to view the installed version of Python.

    python --version

    Notice it is different from the previous step.

  8. With our new configuration verified, let's commit the changes. Use VS Code's source control tools or the below terminal command.

    git add '.devcontainer/devcontainer.json'
    git commit -m 'feat: Add codespace configuration'
    git push
  9. With our dev container configuration committed, Mona will begin checking your work. Give her a moment to provide feedback and the next learning steps.