简体   繁体   English

支持 Docker 的 ASP.NET Core:连接被拒绝

[英]ASP.NET Core with Docker support: Connection refused

I have a ASP .NET Core (v2.0) app with Docker support.我有一个支持 Docker 的 ASP .NET Core (v2.0) 应用程序。 And I want to start a Oracle Database when starting my app.我想在启动我的应用程序时启动一个 Oracle 数据库。 This is how my docker-compose file looks like:这是我的 docker-compose 文件的样子:

version: '3'

services:
  devarttestapp:
    image: devarttestapp
    build:
      context: ./DevartTestApp
      dockerfile: Dockerfile

  oracledb:
    image: sath89/oracle-12c
    ports: 
      - "1521:1521"

I use Devart data provider dotConnect for Oracle.我使用 Devart 数据提供程序 dotConnect for Oracle。

var conn = new Devart.Data.Oracle.OracleConnection();
conn.ConnectionString = Environment.GetEnvironmentVariable("ORACLE_CONNECTION_STRING");
try
{
    conn.Open();
}
catch (Exception e)
{
    Console.WriteLine(e);
    throw;
}

But when I try to connect to the database of the created Oracle DB container I get following exception:但是当我尝试连接到创建的 Oracle DB 容器的数据库时,出现以下异常:

System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (Connection refused 127.0.0.1:1521) System.Net.Internals.SocketExceptionFactory+ExtendedSocketException(连接被拒绝 127.0.0.1:1521)

I also tried to include the depends_on as well as the networks option in my docker-compose file with the same results.我还尝试在我的 docker-compose 文件中包含depends_on 和networks 选项,结果相同。

What could be the cause of this exception?导致此异常的原因可能是什么?
And how do I solve this problem?我该如何解决这个问题?

From within the container, can you send me the output of this command?从容器内,你能把这个命令的输出发送给我吗?

apt-get update && apt-get install nmap -y && nmap -p 1521 localhost

If you are unfamiliar with how to access bash inside the container, this is how:如果您不熟悉如何在容器内访问 bash,请执行以下操作:

Find your container ID or name: docker ps Connect to BASH: docker exec -it >containerID< /bin/bash找到您的容器 ID 或名称: docker ps连接到 BASH: docker exec -it >containerID< /bin/bash

I have a feeling that his issue pertains to Oracle rather than Docker as your docker-compose file looks correct.我有一种感觉,他的问题与 Oracle 而不是 Docker 有关,因为您的 docker-compose 文件看起来是正确的。 Perhaps the listener hasn't been enabled.也许侦听器尚未启用。 I would also appreciate the output of: lsnrctl status if nmap says that the port is not open .我也很感激输出: lsnrctl status if nmap说端口没有open

https://docs.oracle.com/cd/E11882_01/network.112/e41945/listenercfg.htm#NETAG010 https://docs.oracle.com/cd/E11882_01/network.112/e41945/listenercfg.htm#NETAG010

I faced with the same problem on my mac.我在我的 mac 上遇到了同样的问题。 I solved it using port that > 9000.我使用> 9000的端口解决了它。

Just add SslMode=None;只需添加SslMode=None; in your connection string在您的连接字符串中

  "ConnectionStrings": {
    "DefaultConnection": "Server=db-host; Database=db-name; Uid=db-user; Pwd=db-pwd; SslMode=None;"
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM