简体   繁体   English

无法连接到由docker compose启动的.net容器

[英]Cannot connect to .net container started by docker compose

I started a .net service with a mysql database and all containers are running 我使用mysql数据库启动了.net服务,并且所有容器都在运行

109eeaf260e8        authentication_service:latest   "dotnet out/Authenti…"   9 seconds ago       Up 7 seconds        0.0.0.0:5003->80/tcp     authenticationservice_authentication_service_1
5da4ab86b093        mysql:8.0.3                     "docker-entrypoint.s…"   10 seconds ago      Up 8 seconds        0.0.0.0:3305->3306/tcp   authenticationservice_authentication_service_d

Now I send a HTTP request by postman to http://192.168.0.4:5003/api/authentication/5 I tried with :5000 , :80 or authentification_serivce:PORT as well. 现在,我将邮递员的HTTP请求发送到我尝试使用:5000:80authentification_serivce:PORT http://192.168.0.4:5003/api/authentication/5 But always I receive a timeout or a not found. 但总是会收到超时或找不到。

When I start the same by IDE and call http://localhost:5000/api/authentication/5 I receive the expected value. 当我通过IDE启动相同文件并调用http://localhost:5000/api/authentication/5我收到了预期的值。

I tried to work with EXPOSE 80 in my Dockerfile but without success. 我试图与工作EXPOSE 80在我Dockerfile但没有成功。

My docker-compose: 我的码头工人组成:

version: '3.1'

networks:
  overlay:
services:
  authentication_service:
    image: authentication_service:latest
    depends_on:
      - "authentication_service_db"
      - "adminer"
    build:
      context: .
      dockerfile: Dockerfile
    links:
      - authentication_service_db
    ports:
      - 5003:80
    networks:
      - overlay
  authentication_service_db:
    image: mysql:8.0.3
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: authenticationdb
    ports:
      - 3305:3306
    restart: always
    volumes:
      - ./data-authentication:/var/lib/mysql
    networks:
      - overlay
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    networks:
      - overlay

My container is living (and listening) 我的容器正在居住(并且正在聆听)

Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

So I'm confused. 所以我很困惑。 How can I connect to the .net app in my service? 如何连接到服务中的.net应用程序? It seems that my port mapping is wrong or I forgot a basic configuration in my docker-compose or in .net? 看来我的端口映射不正确,或者我忘记了在docker-compose或.net中的基本配置?

(If you need some more configs from project or Dockerfile please leave a comment) (如果您需要项目或Dockerfile中的更多配置,请发表评论)

You are defining a authentication_service with port mapping 您正在使用端口映射定义authentication_service

ports:
      - 5003:80

in your docker-compose.yml. 在您的docker-compose.yml中。 This means that requests on port 5003 on your docker host will be forwarded to port 80 of your authentication_service-container. 这意味着您在Docker主机上端口5003上的请求将被转发到authentication_service-container的端口80。

So (if the container of the authentication_service is really listening on port 80) the URL you have to fire against on your docker host is: 因此(如果authentication_service的容器确实在端口80上侦听),您必须在Docker主机上针对的URL是:

http://localhost:5003/api/authentication/5

暂无
暂无

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

相关问题 Azure 函数 v3 将调试器附加到本地 docker 容器,以 docker-compose (dotnet) 开始 - Azure functions v3 attach debugger to docker container in local started with docker-compose (dotnet) docker组合后无法连接到mysql db - Cannot connect to mysql db after docker compose up Docker环境多容器结构中PostgreSQL和.Net Core的docker-compose文件应该怎么做? - How should be docker-compose file for PostgreSQL and .Net Core in Docker Environment multi-container structure? 为什么我的 .NET Web API 应用程序在使用 docker-compose 时无法连接到 docker 上的 MySQL? - Why does my .NET web API application not connect to MySQL on docker when using docker-compose? 无法从其他容器连接到 Kafka Docker 容器:连接被拒绝 - 1/1 代理已关闭 - Cannot connect to Kafka Docker-container from other container: Connection refused - 1/1 brokers are down .NET 6 docker 容器,带手表 - .NET 6 docker container with watch 应用程序无法连接到 docker 中的 PostgreSQL 撰写 - Application not able to connect to PostgreSQL in docker compose 使用 Docker Compose 在 docker windows 容器中访问网络共享的最佳选择 - Best option to access network share in docker windows container with Docker Compose 从在 Docker Windows 容器中运行的 .Net 4.8 控制台应用程序连接到本地 SQL Server - Connect to local SQL Server from .Net 4.8 Console Application Running in Docker Windows container 如何从 windows Z05B6053C415A2134EAD6 容器中的 .NET 应用程序连接到在主机上运行的 SQL 服务器 - How do you connect to SQL Server running on the host from a .NET app in a windows docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM