昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期三, 三月 14, 2018

Access DB from .Net Core Docker build

When we build to docker container using Visual studio, Visual studio will create a new network for the .net core app. 

You can also setup db in the yml file, so that DB can be created in the same network. 

But If you already have a DB setup in a docker container which is in a different network as I do, how can you access this db?

Here is the solution:

Add your .net core app to both of the network. For example, I have my db container in my-net network. I ran the following command to add the .net app to this network

docker network connect --alias api-host my-net 2802

Then my app container will be in both network with a different hostname




You will also need to update the db settings to point to the correct db hostname







Now, you app can access the db through another network interface.

--
Feng

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.