You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/codespaces/managing-codespaces-for-your-organization/restricting-the-base-image-for-codespaces.md
+20-13Lines changed: 20 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -19,24 +19,32 @@ When you create a codespace, a development container is automatically created on
19
19
You can choose which image you want to use for your codespaces by specifying it in the dev container configuration for a repository. You can do this, for example, by using the `image` property in the `devcontainer.json` file.
For more information, see the [dev containers specification](https://containers.dev/implementors/json_reference/) on the Development Containers website.
25
+
For more information, see the [dev containers specification](https://containers.dev/implementors/json_reference/#image-specific) on the Development Containers website.
26
+
27
+
Alternatively, you can specify the base image in a Dockerfile. For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#dockerfile)."
26
28
27
29
If you don't specify an image in the dev container configuration for a repository, the default dev container image is used. The default image contains a number of runtime versions for popular languages and commonly used tools. For more information, see "[AUTOTITLE](/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#using-the-default-dev-container-configuration)."
28
30
29
31
As an organization owner, you can add a policy to restrict which dev container images can be used for codespaces created within your organization.
30
32
31
-
If the image specified in the dev container configuration does not match one of the allowed images, the following message is displayed when someone tries to create a codespace for the repository:
33
+
If you attempt to create a codespace using a `devcontainer.json` that specifies an image that is not allowed by the policy, the following message is displayed in {% data variables.product.prodname_dotcom_the_website %}:
34
+
35
+
> The codespace cannot be created because the image specified in your dev container configuration is not allowed. You may need to select a different branch, modify your container configuration, or adjust your organization's policy setting.
36
+
37
+
Using the CLI, the error message is:
32
38
33
-
> Codespace could not be created: Base image 'DETAILS FROM DEV CONTAINER CONFIGURATION' is not allowed based on an organization policy set by your organization owner.
39
+
> error creating codespace: HTTP 400: Base image 'IMAGE-REFERENCE' is not allowed based on an organization policy set by your organization administrator.
40
+
41
+
If the image for a codespace is specified in a Dockerfile, and does not match the policy, a codespace is created in recovery mode, using the default recovery container rather than the specified image. A message to this effect is included at the end of the creation log. For more information about the creation log, see "[AUTOTITLE](/codespaces/troubleshooting/github-codespaces-logs#creation-logs)."
34
42
35
43
{% note %}
36
44
37
45
**Notes**:
38
46
- The dev container base image should not be confused with the host image. The host image is the image used to build the virtual machine on which the dev container runs. For more information, see "[AUTOTITLE](/codespaces/setting-your-user-preferences/choosing-the-stable-or-beta-host-image)."
39
-
- The base image policy is only applied when a codespace is created. It is currently not applied when you rebuild a container. This will change in a future release. For more information, see "[AUTOTITLE](/codespaces/getting-started/understanding-the-codespace-lifecycle#rebuilding-a-codespace)."
47
+
- The base image policy is applied when a codespace is created, and when you perform a full container rebuild. For more information, see "[AUTOTITLE](/codespaces/getting-started/understanding-the-codespace-lifecycle#rebuilding-a-codespace)."
40
48
- The base image policy does not apply to the default image, or the image that's used to recover a codespace if an error is introduced into a dev container configuration which prevents the container from being rebuilt.
41
49
42
50
{% endnote %}
@@ -56,18 +64,17 @@ For example, you could create an organization-wide policy that restricts the bas
56
64
{% data reusables.codespaces.codespaces-org-policies %}
57
65
1. Click **Add constraint** and choose **Base images**.
58
66
1. Click {% octicon "pencil" aria-label="Edit policy" %} to edit the constraint.
59
-
1. In the "Allowed values" field, enter the complete URL of an image you want to allow.
67
+
1. In the "Allowed values" field, enter the image reference of the Docker image you want to allow.
60
68
61
-

69
+

62
70
63
-
{% note %}
71
+
You can use the `*` wildcard as the last character of the image reference to match all images that start with the same reference to the left of the wildcard. For example, `mcr.microsoft.com/devcontainers/*`.
64
72
65
-
**Note**: You must specify an image URL that exactly matches the value specified in a dev container configuration.
73
+
1. Click {% octicon "plus" aria-label="Add button" %} to add the value.
74
+
1. If required, repeat the previous two steps to add more image references.
66
75
67
-
{% endnote %}
76
+
When you add multiple image references, if an image reference specified in the dev container configuration of a repository does not match any of the references in a policy that applies to the repository, you will not be able to create codespaces for that repository.
68
77
69
-
1. Click {% octicon "plus" aria-label="Add button" %} to add the value.
70
-
1. If required, repeat the previous two steps to add more image URLs.
71
78
1. Click outside of the dialog box to close it.
72
79
{% data reusables.codespaces.codespaces-policy-targets %}
73
80
1. If you want to add another constraint to the policy, click **Add constraint** and choose another constraint. For information about other constraints, see:
@@ -88,7 +95,7 @@ You can edit an existing policy. For example, you may want to add or remove cons
88
95
1. Display the "Codespaces policies" page. For more information, see "[Adding a policy to define the allowed images](#adding-a-policy-to-define-the-allowed-images)."
Copy file name to clipboardExpand all lines: content/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers.md
+19-11Lines changed: 19 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -77,27 +77,35 @@ The following example uses four instructions:
77
77
78
78
`ARG` defines a build-time variable.
79
79
80
-
`FROM` specifies the parent image on which the generated Docker image will be based.
80
+
`FROM` specifies the parent image on which the generated Docker image will be based. If a base image policy has been configured, allowing only certain images to be used, the specified image must match one of the image references in the policy. If it does not, codespaces for this repository will be created in recovery mode. For more information, see "[AUTOTITLE](/codespaces/managing-codespaces-for-your-organization/restricting-the-base-image-for-codespaces)."
81
81
82
-
`COPY` copies a file and adds it to the filesystem.
82
+
`COPY` copies a file from the repository and adds it to the filesystem of the codespace.
83
83
84
84
`RUN` updates package lists and runs a script. You can also use a `RUN` instruction to install software, as shown by the commented out instructions. To run multiple commands, use `&&` to combine the commands into a single `RUN` statement.
85
85
86
86
```dockerfile copy
87
-
ARG VARIANT="16-buster"
88
-
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
87
+
ARG VARIANT="16"
88
+
FROM mcr.microsoft.com/devcontainers/javascript-node:1-${VARIANT}
89
89
90
-
# [Optional] Uncomment if you want to install an additional version of node using nvm
91
-
# ARG EXTRA_NODE_VERSION=10
92
-
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
90
+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
RUN apt-get update && bash /tmp/scripts/script-in-codespace.sh
99
101
```
100
102
103
+
{% note %}
104
+
105
+
**Note**: In the above example, the script that's copied to the codespace (`script-in-your-repo.sh`) must exist in your repository.
106
+
107
+
{% endnote %}
108
+
101
109
For more information about Dockerfile instructions, see "[Dockerfile reference](https://docs.docker.com/engine/reference/builder)" in the Docker documentation.
Copy file name to clipboardExpand all lines: data/reusables/codespaces/codespaces-policy-targets.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
{% note %}
6
6
7
-
**Note**: If you're adding a constraint to a policy that already contains the "Maximum codespaces per user" constraint, you won't be able to apply the policy to selected repositories. This is because the "Maximum codespaces per user" constraint always applies to all repositories in the organization.
7
+
**Note**: If you're adding a constraint to an existing policy that already contains the "Maximum codespaces per user" constraint, you won't be able to apply the policy to selected repositories. This is because the "Maximum codespaces per user" constraint always applies to all repositories in the organization.
0 commit comments