【问题标题】:how to fix Connection refused [::ffff:127.0.0.1]:port on linux如何修复连接被拒绝 [::ffff:127.0.0.1]:linux 上的端口
【发布时间】:2021-04-24 13:13:40
【问题描述】:

嗨,我使用 .net core 创建项目。我的项目连接到其他项目以获取服务。我阅读 docker-compose 并为项目设置网络。在 windows 操作系统中,我的项目正确连接到其他项目并获取服务。我设置了 ip 127.0.0.1 连接到其他项目。在 linux 中我看到 ip docker 容器项目是这样的

docker network inspect my_project_net

看看

 "IPv4Address": "172.18.0.5/16",
 "IPv6Address": ""

当我的项目连接到其他项目时出现此错误

Connection refused [::ffff:127.0.0.1]:port // port is 105

如何将此端口转换为 127.0.0.1 或正确运行我的项目 感谢您阅读我的问题

【问题讨论】:

    标签: linux docker asp.net-core docker-compose


    【解决方案1】:

    您必须将 docker-compose 中的 container_name 设置为连接到另一个项目的环境项目,例如:

      version: '3.3'
         
        services:
          proj1:
            container_name: proj-1
            image:  ...
            ports:
              - "5002:5002" 
              - "8443:8443"
            environment:
              - ConnectionString=Data Source=127.0.0.1,14330;Initial Catalog=db;
    User  id=sa;Password=******; // in docker-compose you must use (container_name) mssql insted 127.0.0.1
              - ConnectionString=Data Source=mssql,14330;Initial Catalog=db;
    User  id=sa;Password=******; // true 
            restart: always
            depends_on:
              - mssqlservice
            restart: always
          mssqlservice:
            image: 'mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04'
            container_name: mssql
            environment:
              ACCEPT_EULA: Y
              MSSQL_SA_PASSWORD: ******
            volumes:
              - sqlvolume:/var/opt/mssql
            expose:
              - 1433
            ports:
              - "14330:1433"
            restart: always
        volumes:
          sqlvolume:
            driver: local
            name: mssqldata
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-27
      • 2016-12-24
      • 2020-03-06
      • 1970-01-01
      • 2022-06-18
      • 2022-10-05
      • 2019-02-12
      • 2021-11-18
      相关资源
      最近更新 更多