From 0ddf9d096aa7fd111d3d9aa3d8f4c849531222db Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 18 Jan 2026 15:36:22 -0800 Subject: [PATCH] add docker support --- .dockerignore | 5 +++ Catalog26.csproj | 14 +++--- Catalog26.sln | 2 +- Dockerfile | 29 +++++++++++++ README.md | 103 ++++++++++++++++++++++++++++++++++++++++++++ k8s-deployment.yaml | 43 ++++++++++++++++++ 6 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 k8s-deployment.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4a7b046 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +bin/ +obj/ +.vs/ +.git/ +*.user \ No newline at end of file diff --git a/Catalog26.csproj b/Catalog26.csproj index 8fb0da0..a4b4b74 100644 --- a/Catalog26.csproj +++ b/Catalog26.csproj @@ -1,7 +1,7 @@ - net10.0 + net9.0 enable enable @@ -11,13 +11,17 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + diff --git a/Catalog26.sln b/Catalog26.sln index 70bfc36..6dd248e 100644 --- a/Catalog26.sln +++ b/Catalog26.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.14.36705.20 d17.14 +VisualStudioVersion = 17.14.36705.20 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Catalog26", "Catalog26.csproj", "{1C563A4F-E0DC-974E-3438-0A05DCCA15DF}" EndProject diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e21faf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# STAGE 1: Build +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +# Set the working directory in the container +WORKDIR /app + +# Copy the .csproj file and restore any dependencies +# Doing this separately allows Docker to cache this layer +COPY *.csproj ./ +RUN dotnet restore + +# Copy the rest of the application files +COPY . ./ + +# Build the application and publish it for production +RUN dotnet publish -c Release -o /app/publish + +# STAGE 2: Runtime +# Use the ASP.NET runtime image (much smaller than the SDK) +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime +WORKDIR /app + +# Copy the published files from the build stage +COPY --from=build /app/publish . + +# Expose the port your app runs on (usually 8080 in .NET 8+) +EXPOSE 8080 + +# Set the entrypoint for the application +ENTRYPOINT ["dotnet", "Catalog26.dll"] diff --git a/README.md b/README.md index a1d92b4..77be91f 100644 --- a/README.md +++ b/README.md @@ -1 +1,104 @@ # Catalog - Pricing and Availability + +## SQL + +## Docker + +### Create a Local Docker Registry with TLS + +On one of the VMs (e.g oahu.chopark.home), set up a local Docker registry. +Skip if a local registry already exists. + +Prerequisite: Create a CA and a self-signed cert. + +```bash +docker run -d --restart=always --name registry \ + -v /opt/registry/certs:/certs \ + -v /opt/registry/data:/var/lib/registry \ + -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \ + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.crt \ + -e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \ + -p 443:443 \ + registry:2 +``` + +### Build a Docker Image + +1. Create a `Dockerfile`. Refer to the `Dockerfile` in the root of this project. + +2. Then build the image. + +```powershell +# build an image +docker build -t catalog26 . + +# verify the image +docker images | grep catalog26 + +# also try running it +docker run -d -p 5000:8080 -n catalog26 catalog26 +``` + +3. Tag for my registry. + +```powershell +docker tag catalog26 registry.chopark.home/catalog26 +``` + +4. Push to Registry + +```powershell +docker push registry.chopark.home/catalog26 +``` + +Optional: If an https error is returned, make the following adjustments. + +On Linux, edit `/etc/docker/daemon.json`: + +```json +{ + "insecure-registries": ["registry.chopark.home"] +} +``` + +On Windows (Docker Desktop): +- Open Docker Desktop +- Go to Settings > Docker Engine +- Add to the JSON configuration + +```json +{ + "insecure-registries": ["registry.chopark.home"] +} +``` + +## Kubernetes + +1. Containerd (on all K8s nodes) for https connection problem + +```toml +sudo tee /etc/containerd/certs.d/registry.chopark.home/hosts.toml < /dev/null <