Skip to content

Add more instructions - #4413

Merged
richlander merged 11 commits into
dotnet:mainfrom
richlander:extra-instructions
Feb 17, 2023
Merged

richlander merged 11 commits into
dotnet:mainfrom
richlander:extra-instructions

Conversation

@richlander

@richlander richlander commented Feb 12, 2023 •

Copy link
Copy Markdown
Member
  • For building platform-specific images (or not).
  • Enabling (or disabling) globalization (and potentially reducing size)

Please review @tarekgh

@ghost ghost added the area-samples label Feb 12, 2023
Comment thread samples/aspnetapp/Dockerfile.alpine-icu Resolved
Comment thread samples/aspnetapp/Dockerfile.alpine Resolved
Comment thread samples/aspnetapp/README.md Resolved
Comment thread samples/build-for-a-platform.md Resolved

In addition, Docker [Buildkit exposes multiple environment variables](https://github.com/dotnet/dotnet-docker/pull/4387#issuecomment-1416565213) that can be used to further conditionalize behavior. These environment variables can be controlled with the pattern demonstrated in [Dockerfile](https://github.com/mthalman/dredge/blob/main/src/Valleysoft.Dredge/Dockerfile). As mentioned, .NET doesn't support being run in emulation. The pattern in that Dockerfile results in the SDK always being run natively while the final image is affected by the `--platform` switch. This model also has the best performance since the bulk of computation is run natively.

Note: We are enabling the following model in a future release: https://github.com/dotnet/dotnet-docker/issues/4388#issuecomment-1421401384.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make these changes as part of this PR? I think it'd be more appropriate to reference the Dockerfile in this repo rather than the Dredge Dockerfile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to switch that PR to use the new format and then block on merging it until it is ready.

Comment thread samples/build-for-a-platform.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Outdated
docker run --rm -it -e TZ=$(cat /etc/timezone) app
```

This approach enables a container image to be launched matching the host, as opposed to setting the information as part of `docker build`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enables a container image to be launched matching the host

Is that a common practice? In the world of cloud computing, what time zone the host is in seems irrelevant. I did a quick search and couldn't find any examples that use the host time zone. All are either hardcoding it or have it set to an environment variable that can be set dynamically. That approach seems better to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this PR: #4414

What do you think @Clockwork-Muse?

Comment thread samples/aspnetapp/Dockerfile.alpine-icu Resolved
Comment thread samples/aspnetapp/Dockerfile.alpine-icu Outdated
COPY aspnetapp/. .
RUN dotnet publish --use-current-runtime -c Release --self-contained false --no-restore -o /app

# To enable globalization support, see

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording To enable globalization is a bit confusing because globalization is already enabled. Maybe something like To read more about globalization support, see...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

Comment thread samples/build-for-a-platform.md Outdated

## Dockerfiles that build everywhere

The default scenario is using multi-arch tags, which will work in multiple environments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the reader understand the multi-arch nomenclature here? The earlier link referred to these are multi-platform images.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Comment thread samples/build-for-a-platform.md Outdated
docker build -t app .
```

It can be built on any supported operating system and architecture. For example, if built on an Apple M1 machine, Docker will produce a `linux/arm64` image, while on a Windows x64 machine, it will produce a `linux/amd64` image.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while on a Windows x64 machine, it will produce a linux/amd64 image

Not if your windows machine is configured for Windows containers :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I was being lazy.

Comment thread samples/build-for-a-platform.md Outdated

Docker Desktop uses [QEMU](https://www.qemu.org/) for emulation, for example running x64 code on an Arm64 machine. [.NET doesn't support being run in QEMU](https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md#qemu). That means that the SDK needs to always be run natively, to enable [multi-stage build](https://docs.docker.com/build/building/multi-stage/). Multi-stage build is used by all of our samples.

As a result, we need a reliable pattern that enables produces multiple variants of images on one machine, but that doesn't use emulation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken wording - that enables produces multiple variants

@richlander
richlander requested a review from lbussell as a code owner February 14, 2023 15:50
@richlander

Copy link
Copy Markdown
Member Author

I believe I have addressed all feedback.

Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Resolved
Comment thread samples/enable-globalization.md Outdated

### Alpine

Install `tzdata`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is formatted differently than the previous ICU section.

The previous section provided a Dockerfile snippet - e.g. a RUN instruction in a Dockerfile code block. It also didn't have an Install xxx prefix.

Comment thread samples/build-for-a-platform.md Outdated
For Linux containers on an x64 machine:

```bash
$ docker inspect app | jq .[0].Architecture

@MichaelSimons MichaelSimons Feb 17, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker CLI will do this for you and the nice thing is the command is platform agnostic.

docker inspect app -f "{{ .Architecture }}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I submit to being a jq addict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you like translating that into PowerShell 🥲

@richlander

richlander commented Feb 17, 2023 •

Copy link
Copy Markdown
Member Author

I believe I have now addressed the feedback.

Great feedback, BTW.

@richlander
richlander merged commit 10d5312 into dotnet:main Feb 17, 2023
@richlander
richlander deleted the extra-instructions branch February 17, 2023 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants