Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/core/docker/build-container.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Containerize an app with Docker tutorial
description: In this tutorial, you learn how to containerize a .NET application with Docker.
ms.date: 03/15/2024
ms.date: 03/20/2024
ms.topic: tutorial
ms.custom: "mvc"
zone_pivot_groups: dotnet-version-7-8
Expand Down Expand Up @@ -303,8 +303,8 @@ Docker will process each line in the *Dockerfile*. The `.` in the `docker build`

```console
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
counter-image latest 2f15637dc1f6 10 minutes ago 217MB
REPOSITORY TAG IMAGE ID CREATED SIZE
counter-image latest 2f15637dc1f6 10 minutes ago 217MB
```

The `counter-image` repository is the name of the image. The `latest` tag is the tag that is used to identify the image. The `2f15637dc1f6` is the image ID. The `10 minutes ago` is the time the image was created. The `217MB` is the size of the image. The final steps of the _Dockerfile_ are to create a container from the image and run the app, copy the published app to the container, and define the entry point.
Expand All @@ -321,8 +321,8 @@ ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]

```console
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
counter-image latest 2f15637dc1f6 10 minutes ago 208MB
REPOSITORY TAG IMAGE ID CREATED SIZE
counter-image latest 2f15637dc1f6 10 minutes ago 208MB
```

The `counter-image` repository is the name of the image. The `latest` tag is the tag that is used to identify the image. The `2f15637dc1f6` is the image ID. The `10 minutes ago` is the time the image was created. The `208MB` is the size of the image. The final steps of the _Dockerfile_ are to create a container from the image and run the app, copy the published app to the container, and define the entry point.
Expand All @@ -336,9 +336,9 @@ ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]

:::zone-end

The `COPY` command tells Docker to copy the specified folder on your computer to a folder in the container. In this example, the *publish* folder is copied to a folder named *App/out* in the container.
The `FROM` command specifies the base image and tag to use. The `WORKDIR` command changes the **current directory** inside of the container to *App*.

The `WORKDIR` command changes the **current directory** inside of the container to *App*.
The `COPY` command tells Docker to copy the specified source directory to a destination folder. In this example, the *publish* contents in the `build-env` layer were output into the folder named *App/out*, so it's the source to copy from. All of the published contents in the *App/out* directory are copied into current working directory (*App*).

The next command, `ENTRYPOINT`, tells Docker to configure the container to run as an executable. When the container starts, the `ENTRYPOINT` command runs. When this command ends, the container will automatically stop.

Expand Down
26 changes: 20 additions & 6 deletions docs/core/docker/publish-as-container.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: Containerize an app with dotnet publish
description: In this tutorial, you'll learn how to containerize a .NET application with dotnet publish.
ms.date: 01/16/2024
description: In this tutorial, you'll learn how to containerize a .NET application with dotnet publish command and without the use of a Dockerfile.
ms.date: 03/20/2024
ms.topic: tutorial
zone_pivot_groups: dotnet-version-7-8
---

# Containerize a .NET app with dotnet publish

Containers have many features and benefits, such as being an immutable infrastructure, providing a portable architecture, and enabling scalability. The image can be used to create containers for your local development environment, private cloud, or public cloud. In this tutorial, you'll learn how to containerize a .NET application using the [dotnet publish](../tools/dotnet-publish.md) command.
Containers have many features and benefits, such as being an immutable infrastructure, providing a portable architecture, and enabling scalability. The image can be used to create containers for your local development environment, private cloud, or public cloud. In this tutorial, you'll learn how to containerize a .NET application using the [dotnet publish](../tools/dotnet-publish.md) command without the use of a Dockerfile.

## Prerequisites

Expand Down Expand Up @@ -580,7 +580,7 @@ The app command instruction configuration helps control the way the `ContainerEn

### `ContainerUser`

The user configuration property controls the default user that the container runs as. This is often used to run the container as a nonroot user, which is a best practice for security. There are a few constraints for this configuration to be aware of:
The user configuration property controls the default user that the container runs 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 for this configuration to be aware of:

- It can take various forms—username, linux user ids, group name, linux group id, `username:groupname`, and other ID variants.
- There's no verification that the user or group specified exists on the image.
Expand All @@ -602,6 +602,20 @@ The default value of this field varies by project TFM and target operating syste
> [!TIP]
> The `APP_UID` environment variable is used to set user information in your container. This value can come from environment variables defined in your base image (like that Microsoft .NET images do), or you can set it yourself via the `ContainerEnvironmentVariable` syntax.

To configure your app to run as a root user, set the `ContainerUser` property to `root`. In your project file, add the following:

```xml
<PropertyGroup>
<ContainerUser>root</ContainerUser>
</PropertyGroup>
```

Alternatively, you can set this value when calling `dotnet publish` from the command line:

```dotnetcli
dotnet publish -p ContainerUser=root
```

:::zone-end
:::zone pivot="dotnet-7-0"

Expand Down Expand Up @@ -673,8 +687,8 @@ docker images
Consider the following example output:

```console
REPOSITORY TAG IMAGE ID CREATED SIZE
dotnet-worker-image 1.0.0 25aeb97a2e21 12 seconds ago 191MB
REPOSITORY TAG IMAGE ID CREATED SIZE
dotnet-worker-image 1.0.0 25aeb97a2e21 12 seconds ago 191MB
```

> [!TIP]
Expand Down