Skip to content

Commit d93a05b

Browse files
authored
document all remaining items and properties, as well as auth (#201)
* document all remaining items and properties * Add first docs on registry auth * add note to getting started about console apps * Update docs/ContainerCustomization.md
1 parent c5cefd2 commit d93a05b

File tree

3 files changed

+127
-11
lines changed

3 files changed

+127
-11
lines changed

docs/ContainerCustomization.md

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Customizing your container
22

3-
You can control many aspects of the generated container through MSBuild properties. In general, if you could use a command in a Dockerfile to set some configuration, you can do the same via MSBuild.
3+
You can control many aspects of the generated container through MSBuild properties. In general, if you could use a command in a Dockerfile to set some configuration, you can do the same via MSBuild.
44

55
> **Note**
66
> The only exception to this is `RUN` commands - due to the way we build containers, those cannot be emulated. If you need this functionality, you will need to use a Dockerfile to build your container images.
@@ -39,11 +39,10 @@ Be default, we push to the local Docker daemon (annotated by `docker://`), but f
3939
4040
## ContainerImageName
4141

42-
This property controls the name of the image itself, e.g `dotnet/runtime` or `my-awesome-app`.
42+
This property controls the name of the image itself, e.g `dotnet/runtime` or `my-awesome-app`.
4343

4444
By default, the value used will be the `AssemblyName` of the project.
4545

46-
4746
```xml
4847
<ContainerImageName>my-super-awesome-app</ContainerImageName>
4948
```
@@ -65,7 +64,6 @@ By default, the value used will be the `Version` of the project.
6564
<ContainerImageTags>1.2.3-alpha2;latest</ContainerImageTags>
6665
```
6766

68-
6967
> **Note**
7068
> Tags can only contain up to 127 alphanumeric characters, periods, underscores, and dashes. They must start with an alphanumeric character or an underscore. Any other form will result in an error being thrown.
7169
@@ -84,6 +82,7 @@ By default, we use the `/app` directory as the working directory.
8482
This item adds TCP or UDP ports to the list of known ports for the container. This enables container runtimes like Docker to map these ports to the host machine automatically. This is often used as documentation for the container, but can also be used to enable automatic port mapping.
8583

8684
ContainerPort items have two properties:
85+
8786
* Include
8887
* The port number to expose
8988
* Type
@@ -103,23 +102,92 @@ ContainerPort items have two properties:
103102
This item adds a metadata label to the container. Labels have no impact on the container at runtime, but are often used to store version and authoring metadata for use by security scanners and other infrastructure tools.
104103

105104
ContainerLabel items have two properties:
105+
106106
* Include
107107
* The key of the label
108108
* Value
109109
* The value of the label - this may be empty
110110

111+
See [default container labels](#default-container-labels) for a list of labels that are created by default.
112+
111113
```xml
112114
<ItemGroup>
113115
<ContainerLabel Include="org.contoso.businessunit" Value="contoso-university" />
114116
<ItemGroup>
115117
```
116118

117-
## Unsupported properties
119+
## ContainerEnvironmentVariable
120+
121+
This item adds a new environment variable to the container. Environment variables will be accessible to the application running in the container immediately, and are often used to change the runtime behavior of the running application.
122+
123+
ContainerEnvironmentVariable items have two properties:
124+
125+
* Include
126+
* The name of the environment variable
127+
* Value
128+
* The value of the environment variable
129+
130+
```xml
131+
<ItemGroup>
132+
<ContainerEnvironmentVariable Include="LOGGER_VERBOSITY" Value="Trace" />
133+
</ItemGroup>
134+
```
135+
136+
## ContainerEntrypoint
137+
138+
This item can be used to customize the entrypoint of the container - the binary that is run by default when the container is started.
139+
140+
By default, for builds that create an executable binary that binary is set as the ContainerEntrypoint. For builds that do not create an executable binary `dotnet path/to/application.dll` is used as the ContainerEntrypoint.
141+
142+
ContainerEntrypoint items have one property:
143+
144+
* Include
145+
* The command, option, or argument to use in the entrypoint command
146+
147+
```xml
148+
<ItemGroup Label="Entrypoint Assignment">
149+
<!-- This is how you would start the dotnet ef tool in your container -->
150+
<ContainerEntrypoint Include="dotnet" />
151+
<ContainerEntrypoint Include="ef" />
152+
153+
<!-- This shorthand syntax means the same thing - note the semicolon separating the tokens. -->
154+
<ContainerEntrypoint Include="dotnet;ef" />
155+
</ItemGroup>
156+
```
157+
158+
## ContainerEntrypointArgs
159+
160+
This item controls the default arguments provided to the `ContainerEntrypoint`. This should be used when the ContainerEntrypoint is a program that the user might want to use on its own.
161+
162+
By default, no ContainerEntrypointArgs are created on your behalf.
163+
164+
ContainerEntrypointArg items have one property:
165+
166+
* Include
167+
* The option or argument to apply to the ContainerEntrypoint command
168+
169+
```xml
170+
<ItemGroup>
171+
<!-- Assuming the ContainerEntrypoint defined above, this would be the way to update the database by default, but let the user run a different EF command. -->
172+
<ContainerEntrypointArgs Include="database" />
173+
<ContainerEntrypointArgs Include="update" />
174+
175+
<!-- This is the shorthand syntax for the same idea -->
176+
<ContainerEntrypointArgs Include="database;update" />
177+
</ItemGroup>
178+
```
179+
180+
## ASP.NET Core customizations
181+
182+
ASP.NET Core applications have certain defaults that are set to make containers more 'plug and play'.
183+
184+
* A ContainerPort item is set to expose TCP port 80
185+
* The ASPNETCORE_URLS environment variable is set to `http://+:80` to match that port value.
186+
187+
Both of these will be skipped if a custom value is set.
118188

119-
There are many other properties and items that we want to add support for in subsequent previews:
189+
## Default container labels
120190

121-
* Entrypoints
122-
* Entrypoint Arguments
123-
* Environment Variables
191+
Labels are often used to provide consistent metadata on container images. This package provides some default labels to encourage better maintainability of the generated images.
124192

125-
We expect to add them in future versions, so watch this space!
193+
* `org.opencontainers.image.created` is set to the ISO 8601 format of the current UTC DateTime

docs/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ For more information, see [Customizing a container](./ContainerCustomization.md)
2525
> This package only supports Linux containers in this version.
2626
2727
> **Note**
28-
> This package only supports Web projects (those that use the `Microsoft.NET.Sdk.Web` SDK) in this version.
28+
> If you are publishing a console application (or any non-Web project) you will need to add the `/t:PublishContainer` option to the command line above. See [dotnet/sdk-container-builds#141](https://github.com/dotnet/sdk-container-builds/issues/141) for more details.

docs/RegistryAuthentication.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Authenticating to container registries
2+
3+
Interacting with private container registries requires authenticating with those registries.
4+
5+
Docker has established a pattern with this via the [`docker login`](https://docs.docker.com/engine/reference/commandline/login/) command, which is a way of interacting with a Docker config file that contains rules for authenticating with specific registries. This file, and the authentication types it encodes, are supported by Microsoft.Net.Build.Containers for registry authentication. This should ensure that this package works seamlessly with any registry you can `docker pull` from and `docker push`.
6+
7+
## Kinds of authentication
8+
9+
The config.json file contains three kinds of authentication:
10+
11+
* explicit username/password
12+
* credential helpers
13+
* system keychain
14+
15+
### Explicit username/password
16+
17+
The `auths` section of the config.json file is a key/value map between registry names and Base64-encoded username:password strings. In a 'default' Docker scenario, running `docker login <registry> -u <username> -p <password>` will create new items in this map. These kinds of credentials are popular in Continuous Integration systems, where logging in is done by tokens at the start of a run, but are less popular for end-user development machines, where having bare credentials in a file is a security risk.
18+
19+
### Credential helpers
20+
21+
The `credHelpers` section of the config.json file is a key/value map between registry names and the names of specific programs that can be used to create and retrieve credentials for that registry. This is often used when particular registries have complex authentication requirements. In order for this kind of authentication to work, you must have an application named `docker-credential-{name}` on your system's PATH. These kinds of credentials tend to be very secure, but can be hard to setup on development or CI machines.
22+
23+
### System Keychains
24+
25+
The `credsStore` section is a single string property whose value is the name of a docker credential helper program that knows how to interface with the system's password manager. For Windows this might be `wincred` for example. These are very popular with Docker installers for MacOS and Windows.
26+
27+
## Known-supported registries
28+
29+
All of the above mechanisms are supported by this package. When we push or pull from a registry we will incorporate these credential helpers and invoke them to get any necessary credentials the registry asks for.
30+
31+
The following registries have been explicitly tested:
32+
33+
* Azure Container Registry*
34+
* AWS Elastic Container Registry
35+
* GitHub Package Registry
36+
* GitLab Container Registry
37+
* Google Cloud Artifact Registry
38+
* Quay.io
39+
40+
## Known-unsupported registries
41+
42+
* Docker Hub
43+
44+
## Notes for specific registries
45+
46+
### Azure Container Registry
47+
48+
When authenticating to an Azure Container Registry, at this moment only authentication with an admin username and password is supported. This is the same as running `az acr login -n <registry> -u <username> -p <password>`. Token-based login, like `az acr login -n <registry>` is not supported yet.

0 commit comments

Comments
 (0)