docker desktop dapr with zipkin and docker-compose - c#

I'm using dapr with .net on my local and set to use zipkin but it doesn't show the trace

Related

Publishing ASP.NET to Azure app service on Debian CICD runner

I'm trying to migrate an old azure deployment that was previously run on windows and relied on using msdeploy into our CICD pipeline that is using a debian dotnet sdk. Is there a easy way to do this with a publish profile? I can no longer use the old MSDeploy profile, and it appears that using an FTP profile is not supported through the cli, it will only generate a local release folder.
My goal is to be able to call the follwing without additional steps
dotnet publish WebService/WebService.csproj -c Release /p:PublishProfile="sandbox"
I tried converting to an FTP profile using the ftps credentials in azure, however it only publishes into a local folder on the runner when using this profile.

Issues w/ ASP.NET Core app connecting to PostgreSQL on Docker Container

I have pulled and ran a container for PostgreSQL on my Ubuntu Server using Docker, using the instructions from these instructions.
Using Visual Studio on my Windows 10 workstation, I have developed a Blazor Web Page that connects to the PostgreSQL docker container on my Ubuntu Server using Npgsql, and uses it as the back-end. I eventually used Visual Studio's docker image building capabilities to convert my deployed ASP.NET app to a docker container that I want to run on the same Ubuntu server.
Running the container from Visual studio seems to work fine, I am successfully able to load the web page and I'm able to use the PostgreSQL as my back-end. I am also able to connect to the server without using Visual Studio, by just running the deployed image as a container on my workstation.
I want to have the Blazor web page run from the same Ubuntu Server as my PGSQL docker container, but on different containers, so that I can access the app from any computer on my local network. I pushed the container to my repository on Docker, and then pull it on my Ubuntu Server so that it could run on there.
When I run the Blazor App container on Ubuntu, I keep getting the following exception when loading a page that accesses data from my PGSQL container:
System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
---> Npgsql.NpgsqlException (0x80004005): Exception while connecting
---> System.TimeoutException: The operation has timed out.
What I've tried:
Running the container on the same network ("pgnetwork") as the PGSQL container.
With the container running, I was successfully able to connect to my web page onto a page that doesn't use the PGSQL back-end, but it still gives me this exception when loading a page that does.
Installed ping on to the container on my Ubuntu Server, and pinged the PGSQL container. The pings were successful every time.
I am relatively new to Docker and ASP.NET core, and I'm not an IT guy, so any help or ways to troubleshoot this would be very helpful.
EDIT: One more thing I tried: installing the psql client on my docker container and attempting to connect to the PGSQL container using the same parameters as my connection string in my C# program. It wasn't able to connect.

Communicating between docker containers, using docker-compose, .net core api results in SocketException: Connection refused

I'm trying to connect to an API in a docker container, from another container.
I can successfully call the API from the host, using this URL http://localhost:8091/api/quote/1234.
When trying to communicate between the containers I use this URL, http://jobenginequoteservice:80/api/quote/1234. But this causes an error, SocketException: Connection refused.
This is the port config in my docker-compose file
jobenginequoteservice:
image: ***
ports:
- "8091:80"
build:
context: .
dockerfile: Service/Quote/JobEngineQuoteService/Dockerfile
I am debugging this in visual studio, the api is written in .NET Core. I've checked the docker network and both containers are part of the default one created by compose.
Can anyone help? Thanks.

Connect to SQL Server database from a docker container

I have docker for windows installed on my machine. There is a console application targeting .net core 1.0.0 that tries to access a SQL Server database running on a different VM. I can ping the VM running SQL Server from my machine.
When I try to run the console application using dotnet run from the command prompt on my machine it works fine. But when the same application is run inside a docker container I get a message
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 that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: TCP
Provider, error: 40 - Could not open a connection to SQL Server)
I tried using
docker run --add-host sqldemo:<VM running sql server ip here>
but that made no difference.
Assumptions
Microsoft SQL Server 2016
Windows 10 Anniversary Update
Windows Containers
ASP.NET Core application
Add a SQL user to your SQL database.
In MS SQL expand the database
Right click on 'Security / Logins'
Select 'New Login'
Create a user name and password.
Assign a 'Server Role(s)'...I used sysadmin since I'm just testing
Under 'User Mapping' I added my new user to my database and used 'dbo' for schema.
Change SQL Authentication to allow SQL Server Authentication Mode
Right click on your database, select 'Properties / Security / Server Authentication / SQL Server and Windows Authentication Mode' radio button. Restart the MS SQL service.
Update your appsettings.json with your new user name and password
Example
"ConnectionStrings": {
"DefaultConnection": "Server=YourServerName;Database=YourDatabaseName;MultipleActiveResultSets=true;User Id=UserNameYouJustAdded;Password=PassordYouJustCreated"
},
Make sure you remove Trusted_Connection=True.
Create a Docker file
My example Docker file
FROM microsoft/dotnet:nanoserver
ARG source=.
WORKDIR /app
EXPOSE 5000
EXPOSE 1433
ENV ASPNETCORE_URLS http://+:5000
COPY $source .
Publish Application
Running from the same location as the Docker file in an elevated PowerShell
dotnet publish
docker build bin\Debug\netcoreapp1.0\publish -t aspidserver
docker run -it aspidserver cmd
I wanted to run the container and see the output as it was running in PowerShell.
Once the container was up and running in the container at the command prompt I kicked off my application.
dotnet nameOfApplication.dll
If everything went to plan one should be up and running.
You can run a docker container with network settings set to host. Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0.0.1) will refer to the docker host.
docker run --net=host ...
Then you should get the SQL Server database from inside the docker container as you do from your host.
as in this answer
SQL Server instance string connection in Linux Docker
According to Saurabh Singh from Microsoft:
The Instance name support is available in v 1.1 of .Net Core. In v1.0
of .Net Core, Instance names are not supported on OS other than
Windows.
So I don't think you can connect from .Net Core 1.0 running on Linux to an SQL Server using instance name.
Your choices seem to be:
don't use instance name
wait for .Net Core 1.1 (planned for "Fall 2016")
use pre-release version of .Net Core 1.1

How do I host/publish my .Net Core WebAPI on Ubuntu?

I am learning .Net Core.
I have developed WebApplication using ASP.Net MVC and as it can be installed and run on Local IIS.
What's the similar way to Host / Publish .Net Core WebApi in Ubuntu and Linux instead of running on specific port like 5000?
Is docker helpful for that context? If yes then how can I use it?
Is it possible to host / publish without docker? How can i Host / Publish without Docker?
I also read following link and implemented all steps.
Publish to a Linux Production Environment
In above link i am unable to identify what will be the url to access webapi?
As #Pawel has noted, the recommended way to host your .NET Core Web API or ASP.NET Core application is using Kestrel, the webserver which is built into the dotnet core tooling. For development purposes you do not need another webserver to start and test your api.
You do not need Docker to host your web application/API, but should consider it for production hosting because it's a clean, fast way to automate releases and isolate processes.
With Docker the process structure is the same - Docker just hosts and manages the processes. You would have Kestrel running you API in one Docker container, and Nginx (in another container or installed on the base OS) forwarding calls to it.
Hosting your API without Docker
On Ubuntu, use either Nginx (or Apache) to provide your public HTTPS, and configure it to forward requests to your Kestrel server, which typically runs on port 5000. If your server is running a firewall, do not expose port 5000, but open port 443 (HTTPS) on that machine. Setting up Nginx is covered in the article you referenced. As noted, not required just to start and test your Web API.
Kestrel is fast but very simple - eg. it does not support HTTPS (which you should use for a public API, because you will need authentication, and you can't authenticate securely without HTTPS. There are many other reasons to use Nginx/Apache over Kestrel - security, load balancing, reverse proxy capabilies etc.
Simple steps to get just you API running in a development setup
Ensure you are defining the appropriate runtime in you project.json
"runtimes": {
"win7-x64": {},
"win81-x64": {},
"ubuntu.14.04-x64": {},
"debian.8-x64": {}
}
Ensure that your project.json defines "emitEntryPoint": true in the buildOptions section.
Build your project for the platform you will deploy to: dotnet build -r ubuntu.14.04-x64 --build-profile Release
Publish you project for the platform: dotnet publish -r ubuntu.14.04-x64 --configuration Release -o ./bin/Release/Publish
Use the command line as I've shown to build and publish your app for Ubuntu - I have tried in VS 2015 Update 3 and had problems getting it to build for the right runtime
Copy the files in the Publish folder to your Ubuntu VM or server, and add any files you app needs to run, such as appsettings.json.
Ensure that the appropriate .NET Core framework is installed on your Linux machine.
Open a terminal window, sudo -i to get admin rights, cd to the folder where you put your binaries and run your api using : dotnet MyWebApi.dll where MyWebApi.dll is the main output of your build process.
At this point Kestrel should start with the usual message saying what port it is listening on (say, 5000). If it is a headless server, you should be able to call you Web API using curl:
curl http://localhost:5000/whatever/your/api/needs/here
If the Ubuntu box has a GUI (Gnome etc) you should be able to connect to your api with a browser.
If your Ubuntu server is not running a firewall, you should be able to connect to the Web API with a browser from another machine on the same network:
http://<linux-ip-address>:5000/whatever/your/api/needs/here
You can get the IP address of your Ubuntu server by typing ip addr show in a terminal window.
Notes
Managing your firewall is dependent on your Linux distro. If the server is public, you really must run one and use it to shut down access to you Kestrel service.
Setting up Docker is more complicated, too much to add here. Ask a separate question and I will document what I have done.
Note that when you run under IIS on Windows, exactly the same thing is happening: IIS forwards the requests to Kestrel on port 5000 or whatever you specify. Typically IIS is configured (via the web.config file generated by your publish) to start Kestrel when it is needed and keep it running. You could start your app manually on Windows with dotnet MyWebApi.dll and configure IIS to forward to it.
Running as I've described is fine when learning, but for production you would need to define you API to start as a Linux daemon and have Linux restart it if it crashes (Docker can also do this for you). IIS generally takes care of this for you.
Asp.NET Core application use a cross platform application web server called Kestrel. You can run your application with Kestrel directly (e.g. using dotnet run - very useful during devlepment) however it's not recommended expose Kestrel directly to the outside world, so in a production environment you would put IIS in front of your application when running on Windows or nginx when running on Linux. You can find a sample nginx config here: https://github.com/aspnet/ServerTests/blob/dev/test/ServerComparison.FunctionalTests/nginx.conf
You can specify url/port like this (in your "Program.cs" file):
public static void Main(string[] args) {
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://192.168.0.0:8080")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
Replace "192.168.0.0" with the actual ip or url in the UseUrls() method.
In your project directory just open a terminal/console window and run "dotnet run".
Make sure it says "Now listening on: 192.168.0.0:8080" (or the url/ip you put in).
The above example assumes you are using Startup for your startup class

Categories

Resources