From 244dc21e1cd05bcf24d05da6da1e70bae286b342 Mon Sep 17 00:00:00 2001 From: Akella Srinivas Date: Sat, 14 Feb 2026 16:21:43 +0530 Subject: [PATCH] fix(docker): add Dockerfile, .dockerignore, and docker-compose setup Signed-off-by: Akella Srinivas --- crud-app/.dockerignore | 13 +++++++++++++ crud-app/Dockerfile | 23 ++++++++++++++++++++++ crud-app/docker-compose.yml | 39 +++++++++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 crud-app/.dockerignore create mode 100644 crud-app/Dockerfile diff --git a/crud-app/.dockerignore b/crud-app/.dockerignore new file mode 100644 index 0000000..effc8ff --- /dev/null +++ b/crud-app/.dockerignore @@ -0,0 +1,13 @@ +bin/ +obj/ +.vs/ +.vscode/ +*.user +*.suo +*.sln.docstates +keploy/ +img/ +*.md +docker-compose.yml +.gitignore +dotnet-install.sh diff --git a/crud-app/Dockerfile b/crud-app/Dockerfile new file mode 100644 index 0000000..d2d6d7a --- /dev/null +++ b/crud-app/Dockerfile @@ -0,0 +1,23 @@ +# ---- Build Stage ---- +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /src + +# Copy csproj and restore dependencies first (layer caching) +COPY simpleAPI_v1.csproj ./ +RUN dotnet restore simpleAPI_v1.csproj + +# Copy the rest of the source code and build +COPY . ./ +RUN dotnet publish simpleAPI_v1.csproj -c Release -o /app/publish + +# ---- Runtime Stage ---- +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +WORKDIR /app + +COPY --from=build /app/publish . + +# .NET 8 defaults to port 8080 +EXPOSE 8080 +ENV ASPNETCORE_URLS=http://+:8080 + +ENTRYPOINT ["dotnet", "simpleAPI_v1.dll"] diff --git a/crud-app/docker-compose.yml b/crud-app/docker-compose.yml index ee081b9..20e7992 100644 --- a/crud-app/docker-compose.yml +++ b/crud-app/docker-compose.yml @@ -1,12 +1,31 @@ -version: "3.9" services: postgres: - image: postgres:10.5 - container_name: postgresDb - restart: always - environment: - - POSTGRES_DB=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=password - ports: - - '5432:5432' \ No newline at end of file + image: postgres:10.5 + container_name: postgresDb + restart: always + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=password + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + app: + build: + context: . + dockerfile: Dockerfile + container_name: crud-app + restart: on-failure + ports: + - "5249:8080" + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ConnectionStrings__DefaultConnection=Host=postgres;Port=5432;Database=postgres;Username=postgres;Password=password + depends_on: + postgres: + condition: service_healthy