Angular 2+ and ASP.NET Core Web API - How to publish on Heroku?

1

I have applications:

1. Client-side which is Angular 2+/ASP.NET Core project

2. Server-side ASP.NET Core Web Api with MS SQL database (Entity Framework Core)

This apps have configured CORS.

How can I publish both of this apps on Heroku? I started with the server-side using this tutorial https://blog.devcenter.co/deploy-asp-net-core-2-0-apps-on-heroku-eea8efd918b6

But after this step:

docker build -t <image-name> ./bin/release/netcoreapp2.0/publish

I have tried to run this docker image and it doesn't work correctly:

docker run --rm -it -p 8080:8080 treeder/myapp

The app failed. There is some problem with connection to MSSQL...

An error occurred using the connection to database 'sample-app' on server 'localhost'. System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify thatthe instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (Connection refused 127.0.0.1:1433) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:1433

Even command used to login to Heroku Containter Registry doesn't work:

$ heroku container:login 

And it gives me such an error:

heroku container:login unknown flag: --password-stdin See 'docker login --help'. ▸ Error: docker login exited with 125

asp.net
sql-server
angular
heroku
deployment
asked on Stack Overflow Jan 19, 2018 by Michał Ziobro • edited Jan 19, 2018 by Michał Ziobro

1 Answer

0

There could be number of problems.

Asp.net core looks for ASPNETCORE_ENVIRONMENT environment variable to determine type of deployment. If value for the variable is not found, then it will assume that it is running in production environment.

Check you have put your connection string in appsettings.Development.json. Since we are not setting value for the variable when running the image, it is not reading the development setting file.

If you are using localhost for SQL server, then application will try to connect to the SQL server on the port inside container. But SQL server is running on the host and not in the container. You can ask Docker to attach container to host machine.

Also if you are using exact instructions in the article, then you will need to pass it the port number. Try the command below and see if that works.

docker build -t treeder/myapp ./bin/release/netcoreapp2.0/publish docker run --rm -it --expose=8080 -p 8080:8080 -e="PORT=8080" -e="ASPNETCORE_ENVIRONMENT=Development" --network="host" treeder/myapp

answered on Stack Overflow Nov 28, 2018 by Abhijit Amin • edited Nov 28, 2018 by Abhijit Amin

User contributions licensed under CC BY-SA 3.0