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
@@ -5,7 +5,11 @@ You can control many aspects of the generated container through MSBuild properti
5
5
> **Note**
6
6
> 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.
7
7
8
-
## ContainerBaseImage
8
+
## Choosing a base image
9
+
10
+
These properties help the tools determine which image to build your container on top of.
11
+
12
+
### ContainerBaseImage
9
13
10
14
This property controls the image used as the basis for your image. By default, we will infer the following values for you based on the properties of your project:
11
15
@@ -23,7 +27,7 @@ If you set a value here, you should set the fully-qualified name of the image to
23
27
<PropertyGroup>
24
28
```
25
29
26
-
## ContainerFamily
30
+
###ContainerFamily
27
31
28
32
Starting in .NET 8, `ContainerFamily` can be used to choose a different family of Microsoft-provided container images as the base image for your application. When set, this value will be appended to the end of the selected TFM-specific tag, changing the tag provided. For example, to use the Alpine Linux variants of the .NET base images, you can set `ContainerFamily` to `alpine`:
29
33
@@ -37,7 +41,7 @@ which results in a final tag of `8.0-alpine` for a .NET 8-targeting application.
37
41
38
42
This field is very free-form, and often can be used to select different operating system distributions, default package configurations, or any other 'flavor' of changes to a base image. Consult your base image's documentation for more details.
39
43
40
-
## ContainerRuntimeIdentifier
44
+
###ContainerRuntimeIdentifier
41
45
42
46
This property controls the OS and platform used by your container if your [`ContainerBaseImage`](#containerbaseimage) is a 'Manifest List'. Manifest Lists are images that support more than one architecture behind a single, common, name. For example, the `mcr.microsoft.com/dotnet/runtime` image is a manifest list that supports the `linux-x64`, `linux-arm`, `linux-arm64` images.
43
47
@@ -72,7 +76,11 @@ By default, if your project has a RuntimeIdentifier set, that value will be used
72
76
> **Note**
73
77
> Starting in .NET 8, the Microsoft container images will not include the Windows variants of the images in the manifest list. If you need to target Windows, you will need to use a specific image tag as your `<ContainerBaseImage>`, for example `mcr.microsoft.com/dotnet/aspnet:8.0-preview-windowsservercore-ltsc2022` or `mcr.microsoft.com/dotnet/aspnet:8.0-preview-nanoserver-ltsc2022`.
74
78
75
-
## ContainerRegistry
79
+
## Modifying the generated container
80
+
81
+
These properties and items control metadata about the container that's generated for your application.
82
+
83
+
### ContainerRegistry
76
84
77
85
This property controls the destination registry - the place that the newly-created image will be pushed to.
78
86
@@ -84,7 +92,7 @@ Be default, we push to the local Docker daemon (annotated by `docker://`), but y
84
92
</PropertyGroup>
85
93
```
86
94
87
-
## ContainerRepository
95
+
###ContainerRepository
88
96
89
97
This property controls the name of the generated image itself, e.g `dotnet/runtime` or `my-awesome-app`.
90
98
@@ -99,7 +107,7 @@ By default, the value used will be the `AssemblyName` of the project. In previou
99
107
> **Note**
100
108
> Image names consist of one or more slash-delimited segments, each of which can only contain lowercase alphanumeric characters, periods, underscores, and dashes, and must start with a letter or number - any other characters will result in an error being thrown.
101
109
102
-
## ContainerImageTag(s)
110
+
###ContainerImageTag(s)
103
111
104
112
This property controls the tag that is generated for the image. Tags are often used to refer to different versions of an application, but they can also refer to different operating system distributions, or even just different baked-in configuration. This property also can be used to push multiple tags - simply use a semicolon-delimited set of tags in the `ContainerImageTags` property, similar to setting multiple `TargetFrameworks`.
105
113
@@ -128,7 +136,30 @@ By default in .NET 8, the value used will be `latest` - keeping in line with exp
128
136
> **Note**
129
137
> 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.
130
138
131
-
## ContainerWorkingDirectory
139
+
### ContainerLabel
140
+
141
+
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.
142
+
143
+
ContainerLabel items have two properties:
144
+
145
+
* Include
146
+
* The key of the label
147
+
* Value
148
+
* The value of the label - this may be empty
149
+
150
+
See [default container labels](#default-container-labels) for a list of labels that are created by default.
These properties and items control how the generated container is executed.
161
+
162
+
### ContainerWorkingDirectory
132
163
133
164
This property controls the working directory of the container - the directory that commands are executed within if not other command is run.
134
165
@@ -140,7 +171,7 @@ By default, we use the `/app` directory as the working directory.
140
171
</PropertyGroup>
141
172
```
142
173
143
-
## ContainerPort
174
+
###ContainerPort
144
175
145
176
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.
146
177
@@ -168,26 +199,8 @@ ContainerPort items have two properties:
168
199
> **Note**
169
200
> This item typically does not influence running the container directly - most runtimes will still need to explicitly assign port mappings. Some tooling, like the Docker Tools for Visual Studio Code, will read this data and automatically open ports on your behalf.
170
201
171
-
## ContainerLabel
172
202
173
-
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.
174
-
175
-
ContainerLabel items have two properties:
176
-
177
-
* Include
178
-
* The key of the label
179
-
* Value
180
-
* The value of the label - this may be empty
181
-
182
-
See [default container labels](#default-container-labels) for a list of labels that are created by default.
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.
193
206
@@ -204,7 +217,23 @@ ContainerEnvironmentVariable items have two properties:
204
217
</ItemGroup>
205
218
```
206
219
207
-
## ContainerEntrypoint
220
+
## Controlling the container's commands
221
+
222
+
By default, the container tools will launch your application using either the generated AppHost binary for your application (if your application uses an AppHost), or the `dotnet` command plus your application's DLL. However, you can control how your application is executed by using some combination of `ContainerAppCommand`, `ContainerAppCommandArgs`, `ContainerDefaultArgs`, and `ContainerAppCommandInstruction`.
223
+
224
+
We have these different configuration points because different base images use different combinations of the container Entrypoint and Command properties, and we want to be able to support all of them. Our defaults should be useable for most apps, but if you want to customize your app launch behavior you should:
225
+
226
+
* identify the binary to run and set it as `ContainerAppCommand`
227
+
* identify which arguments are _required_ for your application to run and set them as `ContainerAppCommandArgs`
228
+
* identify which arguments (if any) are _optional_ and could be overridden by a user and set them as `ContainerDefaultArgs`
229
+
* set `ContainerAppCommandInstruction` to `DefaultArgs`
230
+
231
+
More detail on each of these configuration points is detailed below:
232
+
233
+
### ContainerEntrypoint
234
+
235
+
> **Note**
236
+
> In .NET 8 this item is deprecated. See [ContainerAppCommand](#containerappcommand) for more details.
208
237
209
238
This item can be used to customize the entrypoint of the container - the binary that is run by default when the container is started.
210
239
@@ -226,7 +255,10 @@ ContainerEntrypoint items have one property:
226
255
</ItemGroup>
227
256
```
228
257
229
-
## ContainerEntrypointArgs
258
+
### ContainerEntrypointArgs
259
+
260
+
> **Note**
261
+
> In .NET 8 this item is deprecated. See [ContainerAppCommandArgs](#containerappcommandargs) for more details.
230
262
231
263
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.
232
264
@@ -248,7 +280,84 @@ ContainerEntrypointArg items have one property:
248
280
</ItemGroup>
249
281
```
250
282
251
-
## ContainerUser
283
+
### ContainerAppCommand
284
+
285
+
This item is the logical entry point of your application. For most apps, this will be the 'apphost' - the generated executable binary for your application. If your application doesn't generate an apphost, then this command will typically be `dotnet <your project dll>`. These values will be applied after any Entrypoint in your base container, or directly if no Entrypoint is defined.
286
+
287
+
ContainerAppCommand items have one property:
288
+
289
+
* Include
290
+
* The command, option, or argument to use in the entrypoint command
291
+
292
+
```xml
293
+
<ItemGroupLabel="ContainerAppCommand Assignment">
294
+
<!-- This is how you would start the dotnet ef tool in your container -->
295
+
<ContainerAppCommandInclude="dotnet" />
296
+
<ContainerAppCommandInclude="ef" />
297
+
298
+
<!-- This shorthand syntax means the same thing - note the semicolon separating the tokens. -->
299
+
<ContainerAppCommandInclude="dotnet;ef" />
300
+
</ItemGroup>
301
+
```
302
+
303
+
### ContainerAppCommandArgs
304
+
305
+
This item represents any logically-required arguments for your application that should be applied to the `ContainerAppCommand`. By default, none are generated for an application. If present, these will always be applied to your container when it is run.
306
+
307
+
ContainerAppCommandArgs items have one property:
308
+
309
+
* Include
310
+
* The option or argument to apply to the ContainerAppCommand command
311
+
312
+
```xml
313
+
<ItemGroup>
314
+
<!-- Assuming the ContainerAppCommand defined above, this would be the way to force the database to update. -->
315
+
<ContainerAppCommandArgsInclude="database" />
316
+
<ContainerAppCommandArgsInclude="update" />
317
+
318
+
<!-- This is the shorthand syntax for the same idea -->
This item represents any user-overrideable arguments for your application. This is a good way to provide any defaults that your app might need to run in a way that makes it easy to start your application, but still easy to customize.
326
+
327
+
ContainerDefaultArgs items have one property:
328
+
329
+
* Include
330
+
* The option or argument to apply to the ContainerAppCommand command
331
+
332
+
```xml
333
+
<ItemGroup>
334
+
<!-- Assuming the ContainerAppCommand defined above, this would be the way to force the database to update. -->
335
+
<ContainerDefaultArgsInclude="database" />
336
+
<ContainerDefaultArgsInclude="update" />
337
+
338
+
<!-- This is the shorthand syntax for the same idea -->
339
+
<ContainerDefaultArgsInclude="database;update" />
340
+
</ItemGroup>
341
+
```
342
+
343
+
344
+
### ContainerAppCommandInstruction
345
+
346
+
> **Note**
347
+
> This is advanced stuff - most applications shouldn't need to customize their entrypoint to this degree. We'd love to hear more about your use case at https://github.com/dotnet/sdk-container-builds/discussions.
348
+
349
+
This property helps control the way the `ContainerEntrypoint`, `ContainerEntrypointArgs`, `ContainerAppCommand`, `ContainerAppCommandArgs`, and `ContainerDefaultArgs` are combined to form the final command that is run in the container. This depends greatly on if an Entrypoint is present in the base image. This property can take one of three values: "DefaultArgs", "Entrypoint", or "None".
350
+
351
+
* Entrypoint
352
+
* In this mode, the entrypoint is purely defined by `ContainerAppCommand`, `ContainerAppCommandArgs`, and `ContainerDefaultArgs`.
353
+
* None
354
+
* In this mode, the entrypoint is purely defined by `ContainerEntrypoint`, `ContainerEntrypointArgs`, and `ContainerDefaultArgs`.
355
+
* DefaultArgs
356
+
* This is the most complex mode - if none of the `ContainerEntrypoint[Args]` items are present, we defer to `ContainerAppCommand[Args]` and `ContainerDefaultArgs` to create the entrypoint and command - skipping the base image entrypoint for base images that have it hard-coded to `dotnet` or `/usr/bin/dotnet` so that you have complete control.
357
+
* If both `ContainerEntrypoint` and `ContainerAppCommand` are present, then `ContainerEntrypoint` becomes the entrypoint, and `ContainerAppCommand` becomes the command.
358
+
359
+
360
+
### ContainerUser
252
361
253
362
This item controls the default user that the container will run as. This is often used to run the container as a non-root user, which is a best practice for security. There are a few constraints to know about this field:
0 commit comments