Browse Source

Docker compose

Ahmed Elkenany 10 months ago
parent
commit
562fff7be2
2 changed files with 47 additions and 6 deletions
  1. 7 6
      MTWorkHR.API/Program.cs
  2. 40 0
      docker-compose.yml

+ 7 - 6
MTWorkHR.API/Program.cs

@@ -10,7 +10,8 @@ using MTWorkHR.Core.Global;
 var builder = WebApplication.CreateBuilder(args);
 
 // Add services to the container.
-builder.Services.AddDbContext<HRDataContext>(options => {
+builder.Services.AddDbContext<HRDataContext>(options =>
+{
     options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 var config = new AppSettingsConfiguration();
@@ -28,11 +29,11 @@ builder.Services.AddSwaggerGen();
 var app = builder.Build();
 
 // Configure the HTTP request pipeline.
-if (app.Environment.IsDevelopment())
-{
-    app.UseSwagger();
-    app.UseSwaggerUI();
-}
+// if (app.Environment.IsDevelopment())
+// {
+app.UseSwagger();
+app.UseSwaggerUI();
+// }
 
 app.UseHttpsRedirection();
 app.UseAuthentication();

+ 40 - 0
docker-compose.yml

@@ -0,0 +1,40 @@
+version: '3.8'
+
+networks:
+  dev:
+    driver: bridge
+
+services:
+  mt-app:
+    image: docker.io/library/hr
+    depends_on:
+      - "mt-db"
+    container_name: mt-app-services
+    ports:
+      - "8080:80"
+    build:
+      context: .
+      dockerfile: Dockerfile
+    environment:
+      - ConnectionStrings__MTWorkHRConnectionString=Server=mt-db;Database=MTWorkHRDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true;Integrated Security=True;Encrypt=False;
+      - ASPNETCORE_URLS=http://+80
+    networks:
+      - dev
+  mt-db:
+    image: mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04
+    container_name: mt-db
+    user: root
+    environment:
+      SA_USER: "sa"
+      SA_PASSWORD: "p@ssw0rd"
+      SA_DATABASE: "MTWorkHRDB"
+      ACCEPT_EULA: "Y"
+    ports:
+      - "1433:1433"
+    restart: always
+    volumes:
+      - app_data:/var/opt/mssql/data
+    networks:
+      - dev
+volumes:
+  app_data: