[英]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
, :80
或authentification_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.