How can I add dbmigration in docker file - abp

I want to add DB migration also in my docker build image as as first step and then I want to up my application.

It is a console application and you can use the aspnet:7.0 base image.
Here is a sample how you can create an image on your local machine with sdk installed:
FROM mcr.microsoft.com/dotnet/aspnet:7.0
COPY bin/Release/net7.0/publish/ app/
WORKDIR /app
ENTRYPOINT ["dotnet", "MyApp.DbMigrator.dll"]
You need to run dotnet publish -c Release in your DbMigrator folder to populate the release folder.

Related

Unable to connect to SQL Server using EF Core when running app in Docker

I am having a problem connecting to an SQL Server instance running on my local machine. I am using EF Core and I am running my app in Docker. When I try to obtain data from the database I get the following exception:
Here is my connection string configuration:
builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(
"Server=.\\SQLEXPRESS;Database=Cars;Trusted_Connection=True;TrustServerCertificate=True;"));
and here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Cars.Api/Cars.Api.csproj", "Cars.Api/"]
RUN dotnet restore "Cars.Api/Cars.Api.csproj"
COPY . .
WORKDIR "/src/Cars.Api"
RUN dotnet build "Cars.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Cars.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Cars.Api.dll"]
It should also be noted that everything works perfectly fine when I run the project as a console application.
If you need any additional information or clarification, please feel free to ask me.
Any help would be greatly appreciated.
Thanks!

Create Docker Image for ReactJS and Asp.net core

I am taking baby steps in Docker. It will be good for me if anyone describe me the steps for deploying code on docker. My frontend application is in ReactJS and backend application is in .net core. I want to create Image file for it.
Both Docker and Microsoft has some guides on building and hosting ASP.NET Core in docker which is the first step you need to do:
Dockerize an ASP.NET Core application
Docker images for ASP.NET Core
If you want to include your ReactJS client in the image and use ASP.NET Core to host it:
Build your ReactJS client
Include it in the docker image by copying the client files to the wwwroot of you ASP.NET Core application either before building the server or as a part of the docker build process.
Here's how it looks for one of my project, you may be able to modify it for your needs:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS restore
WORKDIR /src
RUN dotnet restore "YourProject.Web/YourProject.Web.csproj"
FROM restore as build
COPY . .
WORKDIR "/src/YourProject.Web"
RUN dotnet build "YourProject.Web.csproj" -c Debug --no-restore -o /app
FROM build AS publish
RUN dotnet publish "YourProject.Web.csproj" -c Debug --no-restore -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
COPY ./ReactClientFiles ./wwwroot
ENTRYPOINT ["dotnet", "YourProject.Web.dll"]
Make sure ASP.NET Core is setup to host static files.

How to save build from Docker Container?

I use Volumes! But smth went wrong.
My web-app config:
And if I use volumes: -"../web/build:/web/build" it doesn't work.
My NGINX config:
I start docker-compose up --build and see that build is complete in /build. I use RUN ls /build to check it. All is correct.
But when I check on server (not in Docker) web/build - folder is created, but is empty.
Why? How can I save build to use it in NGINX?
My Dockerfile for web-app:
in your dockerfile add name to the first image builder for example then use it to copy the files to nginx
FROM node:13.13.0 as builder
WORKDIR .
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx
COPY --from=builder /build /usr/share/nginx/html

How to modify default visual studio generate dockerfile to include running SQLServer Linux?

I have been experimenting with docker to :
1.Create sql server linux containers
2.Adding docker support to existing .net core 2.1 app
When I add the docker support for existing app using visual studio, it generates the necessary default docker file to get the app up and running in container:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY RTMGMTCore2/RTMGMTCore2.csproj RTMGMTCore2/
RUN dotnet restore RTMGMTCore2/RTMGMTCore2.csproj
COPY . .
WORKDIR /src/RTMGMTCore2
RUN dotnet build RTMGMTCore2.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish RTMGMTCore2.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "RTMGMTCore2.dll"]
Is there any easy way to modify this file to include running of a SQL Server linux container to:
1.Bring up SQL server in same container?
2.Bring up SQL server in a different container?
Havent had luck so far with most existing examples out there, because they assume creating the dockerfile from scratch. My ultimate intent is to create a container to demo an the app and it is dependent on a sql server datasource- so I was thinking of maybe an express version of sql server linux if that exists.
Anyone have a quick example of how to do this modifying the existing visual studio created default dockerfile?
Thanks!

Can't run webapplication on tomcat using Docker

I am trying to show on my browser the webapp I've created for a school project.
First of all, I've put my Dockerfile and my .war file in the same folder /home/giorgio/Documenti/dockerProject. I've written in my Dockerfile the following:
# Pull base image
From tomcat:7-jre7
# Maintainer
MAINTAINER "xyz <xyz#email.com">
# Copy to images tomcat path
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY file.war /home/giorgio/Documenti/apache-tomcat-7.0.72/webapps/
Then I've built the image with the command from the ubuntu shell:
docker build -t myName /home/giorgio/Documenti/dockerProjects
Finally, I've run on the shell:
docker run --rm -it -p 8080:8080 myName
Now, everything works fine and it doesn't show any errors, however when I want to reach localhost:8080 from my browser anything shows up, nevertheless tomcat has started running perfectly fine.
Any thoughts about a poossible problem which I can't see?
Thank you!
This is your whole Dockerfile?
Because You just remove all ROOT content (step #3)
then copy war file with your application (step #4) - probably wrong folder in the question only (should be /usr/local/tomcat/webapps/)
But I don't see any endpoint or start foreground application.
I suppose you need to add:
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]
and with that just run tomcat. And It is routines to EXPOSE port, but when you are using -p docker does an implicit exposing.
So your Dockerfile should looks like:
# Pull base image
From tomcat:7-jre7
# Maintainer
MAINTAINER "xyz <xyz#email.com">
# Copy to images tomcat
RUN rm -rf /usr/local/tomcat/webapps/ROOT
# fixed path for copying
COPY file.war /usr/local/tomcat/webapps/
# Routine for me - optional for your case
EXPOSE 8080
# And run tomcat
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

Resources