# Containerizing a WebMap .Net Application with Docker

By encapsulating your .NET Framework application within a Docker container, you gain advantages such as isolation, reproducibility, and scalability. This step-by-step guide will walk you through the process of creating a Docker image for your application, allowing it to run seamlessly on any system equipped with Docker.

#### Prerequisites

1. **Install Docker:** Ensure that Docker is installed on your machine. You can download Docker from the official website: [Docker Engine](https://docs.docker.com/engine/install/).

#### Steps

1. **Deploy the application:** We just need the published application (the binaries or dlls of the project) therefore we would need to execute the following commands (open a terminal in root of the project): `dotnet restore && dotnet publish -c Release -o out` **Skip this step if you already have the binaries**. You have to see something like that: ![](/files/XkgLm88GXdpNNVxSnIvu)
2. **Dockerfile:** Put the dockerfile in the root of the output or binaries folder.  &#x20;

```docker
# Use the official .NET SDK image as a build environment
# You can find the latest version of the SDK here: https://hub.docker.com/r/microsoft/dotnet-sdk 
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build 

# Set the working directory inside the container
WORKDIR /app

# Set the ASPNETCORE_URLS variable
# You can set whatever port you want
# ENV ASPNETCORE_URLS=http://0.0.0.0:<PORT>
ENV ASPNETCORE_URLS=http://0.0.0.0:80

#Expose the same port that was assigned in the ASPNETCORE_URLS
EXPOSE 80

# Copy the binaries app folder in the root
COPY deploy .

# Set the entrypoint
ENTRYPOINT ["dotnet", "app/yourApp.dll"]
```

3. **Build the docker image:** Open a command prompt or terminal in the directory where your `Dockerfile` is located, and run the following command to build the Docker image:

```bash
docker build -t <your-image-name> .
```

Replace `"your-image-name"` with a meaningful name for your Docker image.

4. **Run the docker container:** Once the image is built, you can run the container from it:

{% code fullWidth="false" %}

```bash
docker run -d -p <EXTERNAL_PORT>:<EXPOSED_PORT> --name <your-container-name> <your-image-name>
```

{% endcode %}

5. **Test the containerized application:** Visit `http://localhost:<EXTERNAL_PORT>` in your web browser to test your WebMap .NET Framework application running inside the Docker container. In case the localhost doesn't shows nothing, we have to find the ip container. Just execute the following command:&#x20;

```bash
docker inspect '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <your-container-name>
```

### Create a container with a .yaml file

Another way around to skip those commands and just execute one script is using a .yaml file.&#x20;

#### Prerequisites

* Install [docker-compose](https://docs.docker.com/compose/install/)

#### Steps

1. Create a .yaml file&#x20;

```yaml
version: '3.8'
services:
  my_service:
    container_name: <CHOOSE_CONTAINER_NAME>
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "<EXTERNAL_PORT>:<INTERNAL_PORT_EXPOSE>" # Example port mapping, adjust as needed
```

2. Execute the following command

```bash
docker compose up --build
```

3. Finally, you already created a WebMap application container without executing a lot of commands.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gapvelocity.ai/webmap/scalability/containerizing-a-webmap-.net-application-with-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
