This documentation provides a detailed guide focusing on the configuration of Docker within the development environment for the stevedunn/vogen.serialization project.

Overview

Docker is utilized to create a consistent development environment that isolates the application and its dependencies. The following sections outline the essential steps and configurations required to set up Docker for local development.

Prerequisites

Ensure that the following are installed on your local machine:

  • Docker Desktop
  • Docker Compose
  • Visual Studio or a suitable C# IDE

Step 1: Create a Dockerfile

A Dockerfile defines the environment your application will run in. Create a Dockerfile in the root of the vogen.serialization project directory.

Here’s an example of what the Dockerfile might look like:

# Use the official .NET SDK image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

# Set the working directory
WORKDIR /app

# Copy the *.csproj and restore any dependencies (via `dotnet restore`)
COPY *.csproj ./
RUN dotnet restore

# Copy the entire project
COPY . ./

# Build the project
RUN dotnet build -c Release -o output

# Publish the application
RUN dotnet publish -c Release -o out

# Generate the runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0

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

# Entry point of the application
ENTRYPOINT ["dotnet", "vogen.serialization.dll"]

In this Dockerfile:

  • The first stage builds the application using the .NET SDK.
  • The second stage creates a lightweight image with the published application.

Step 2: Create a Docker Compose File

Docker Compose is used for defining and running multi-container Docker applications. Create a docker-compose.yml file in your project directory.

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

In this configuration:

  • The build context is set to the current directory.
  • The application will be accessible on port 5000.
  • The environment variable for ASP.NET Core is set to Development, enabling developer-friendly features.

Step 3: Build the Docker Image

To build the Docker image defined in your Dockerfile and docker-compose, use the command:

docker-compose build

This command compiles the application and generates the Docker image based on the specifications in the Dockerfile and Docker Compose file.

Step 4: Run the Application

After building the image, run your application using:

docker-compose up

This command starts the application and listens for requests on the specified port. You should see logs indicating that the application is up and running.

To stop the application, use:

docker-compose down

Step 5: Developing with Docker

For efficient development, you can use volumes in your Docker Compose configuration. This allows you to make changes to your code locally and have those changes immediately reflected in the running container. The volume configuration in the above Docker Compose file achieves this.

Hot Reload Configuration

To enable hot reload features with ASP.NET Core, ensure that the environment variable for ASP.NET Core is set to Development. This allows for changes to be reflected immediately without requiring a restart.

Conclusion

Configuring Docker within the development environment for stevedunn/vogen.serialization simplifies the setup and enhances the developer experience. By following these steps, including the creation of a Dockerfile and docker-compose setup, developers can ensure a consistent and isolated environment that mirrors production settings without leaving the development stage.

References