Home Explore Blog CI



docker

1st chunk of `content/guides/dotnet/containerize.md`
860d80b80024885aac350aea26f33b3f548bc40a42c672a50000000100000826
---
title: Containerize a .NET application
linkTitle: Containerize your app
weight: 10
keywords: .net, containerize, initialize
description: Learn how to containerize an ASP.NET application.
aliases:
- /language/dotnet/build-images/
- /language/dotnet/run-containers/
- /language/dotnet/containerize/
- /guides/language/dotnet/containerize/
---

## Prerequisites

* You have installed the latest version of [Docker
  Desktop](/get-started/get-docker.md).
* You have a [git client](https://git-scm.com/downloads). The examples in this
  section use a command-line based git client, but you can use any client.

## Overview

This section walks you through containerizing and running a .NET
application.

## Get the sample applications

In this guide, you will use a pre-built .NET application. The application is
similar to the application built in the Docker Blog article, [Building a
Multi-Container .NET App Using Docker
Desktop](https://www.docker.com/blog/building-multi-container-net-app-using-docker-desktop/).

Open a terminal, change directory to a directory that you want to work in, and
run the following command to clone the repository.

```console
$ git clone https://github.com/docker/docker-dotnet-sample
```

## Initialize Docker assets

Now that you have an application, you can use `docker init` to create the
necessary Docker assets to containerize your application. Inside the
`docker-dotnet-sample` directory, run the `docker init` command in a terminal.
`docker init` provides some default configuration, but you'll need to answer a
few questions about your application. Refer to the following example to answer
the prompts from `docker init` and use the same answers for your prompts.

```console
$ docker init
Welcome to the Docker Init CLI!

This utility will walk you through creating the following files with sensible defaults for your project:
  - .dockerignore
  - Dockerfile
  - compose.yaml
  - README.Docker.md

Let's get started!

? What application platform does your project use? ASP.NET Core
? What's the name of your solution's main project? myWebApp

Title: Containerizing a .NET Application: Prerequisites, Overview, and Sample Application Setup
Summary
This guide provides instructions on how to containerize and run a .NET application using Docker. It outlines the prerequisites, which include having Docker Desktop and a git client installed. The guide uses a pre-built .NET application as an example, which can be obtained by cloning the specified GitHub repository. The guide further explains how to use `docker init` command to generate the required Docker assets to containerize your application, while prompting the user for necessary inputs.