.Net Core on Heroku with Docker
Here's another way you could make this work with Heroku.
Create a Dockerfile in the root of your solution
#https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetappFROM microsoft/dotnet:2.1-sdk AS buildWORKDIR /appCOPY . .CMD ASPNETCORE_URLS=http://*:$PORT dotnet [THE NAME OF YOUR FILE].dll
Create a simple batch file (Assumed Windows OS) called "publish.bat"
NOTE - When dotnet clean is ran, it doesn't clean out the publish folder. I recommend you delete the contents of the directory before publishing. You can add it to the batch file as you see fit.
REM - This file assumes that you have access to the application and that you have docker installedREM : Setup your applications name belowSET APP_NAME=""REM - Delete all files and folders in publishdel /q ".\bin\Release\netcoreapp2.1\publish\*"FOR /D %%p IN (".\bin\Release\netcoreapp2.1\publish\*.*") DO rmdir "%%p" /s /qdotnet clean --configuration Releasedotnet publish -c Releasecopy Dockerfile .\bin\Release\netcoreapp2.1\publish\cd .\bin\Release\netcoreapp2.1\publish\call heroku container:logincall heroku container:push web -a %APP_NAME%call heroku container:release web -a %APP_NAME%
From the root of your solution, now just run publish.bat
c:\dev\my-amazing-app\publish.bat
Information:
- Heroku - Docker Instructions: https://devcenter.heroku.com/articles/container-registry-and-runtime
SOLUTION
First: Replace the docker tag
and docker push
commands with:
heroku container: push web -a <app-name>
That's when I discovered that the heroku registry connection was not set up.
Command to configure:
heroku container: login
This command only works with windows on the default terminal (does not work in cmder with bash).
or the command
docker login --username = _ --password = $ (heroku auth: token) registry.heroku.com
Now, just carry out the following commands.
Push
heroku container: push web -a <app-name>//example:heroku container: push web -a sample-web-carlos
Release
heroku container: release web -a <app-name>//example:heroku container: release web -sample-web-carlos
read more:
https://github.com/heroku/heroku-container-registry/issues/45
https://devcenter.heroku.com/articles/container-registry-and-runtime
Thank mohsin Mehmood for your help!
Ok I managed to figure it out https://simple-web-mohsin.herokuapp.com/api/values
- No need for
ENTRYPOINT ["dotnet", "Blogifier.Web.dll"]
change as suggested above. - After docker push command, you need to run release command as per this
So run the following command after docker push command
heroku container:release web --app={app name}
for my case it was
heroku container:release web --app=simple-web-mohsin
Note: word web in above command is process type and needs to be input as it is.