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
没有评论:
发表评论