Overview

This document outlines the usage of Docker within the development environment of the stevedunn/oglr project. This guide assumes familiarity with both Docker and C# programming.

Setting Up Docker for Local Development

To begin, ensure that you have Docker installed on your machine. This includes both the Docker Engine and Docker Compose.

Dockerfile

The Dockerfile describes the environment in which the C# application will run. It typically looks something like this:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet build -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime

WORKDIR /app
COPY --from=build /app/out .

ENTRYPOINT ["dotnet", "YourApp.dll"]

This Dockerfile consists of two stages:

  1. Build Stage: Uses the .NET SDK image to restore dependencies and build the project.
  2. Runtime Stage: Uses the .NET runtime image to run the application.

docker-compose.yml

The docker-compose.yml file allows you to define and run multi-container Docker applications. Below is an example configuration:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "5000:80"
    volumes:
      - .:/app
    environment:
      - ASPNETCORE_ENVIRONMENT=Development

Key components of the docker-compose.yml file include:

  • services: Defines the individual containers that are part of the application.
  • build: Specifies the context and the Dockerfile to use.
  • ports: Maps port 5000 on the host to port 80 in the container.
  • volumes: Mounts the current directory into the /app folder in the container for live-reloading during development.
  • environment: Sets the ASP.NET Core environment to Development.

Building the Docker Image

From the root of the project, the following command will build the Docker image:

docker-compose build

This command uses the configurations defined in the docker-compose.yml file and the Dockerfile.

Running the Application

To run the application defined in the docker-compose.yml, execute the following command:

docker-compose up

This command will start the service, and you should be able to access the application at http://localhost:5000.

Stopping the Application

To stop the application, use:

docker-compose down

This will stop the running containers and remove them.

Setting Up for Debugging

For debugging purposes, you may want to attach a debugger to the running application. Ensure you have Visual Studio or Visual Studio Code with the necessary extensions installed.

In Visual Studio Code, you may need to add a .vscode/launch.json configuration to attach to the Docker container:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Docker .NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}",
      "sourceFileMap": {
        "/app": "${workspaceFolder}"
      }
    }
  ]
}

This configuration will allow you to attach the debugger to the application running in the Docker container.

Conclusion

This guide provides an overview of how to configure Docker for development in the stevedunn/oglr project, complete with examples for the Dockerfile and docker-compose.yml. Following these instructions allows effective orchestration of the application in a containerized environment.

Source: the above information is taken directly from the project context and known conventions for Docker with .NET applications.