Docker containers requests return Error: read ECONNRESET
Docker containers requests return Error: read ECONNRESET
我正在使用 docker-compose 来启动两个容器:一个带有 micronaut 服务,一个带有 postgres。
这是我的docker-compose.yml
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build:
context: .
network: bridge
ports:
- "8081:8080"
depends_on:
- db
links:
- "db"
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
db:
image: "postgres"
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
但是当我尝试向我的端点之一发送请求时,什么也没有发生,直到最终我收到错误:读取 ECONNRESET
当然,当我 运行 我的应用程序在 docker 之外的电脑上时,我可以正常发送请求。我的设置有问题吗?
其他设置工作正常,但我想知道如何让两个容器像我的第一个 docker-compose 一样连接并能够从我的主机访问它们。
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build: .
depends_on:
- db
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
network_mode: host
db:
image: "postgres"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
network_mode: host
我终于明白了!
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build: .
ports:
- "8080:8080"
depends_on:
- db
links:
- "db"
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
network_mode: bridge
db:
image: "postgres"
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
network_mode: bridge
我正在使用 docker-compose 来启动两个容器:一个带有 micronaut 服务,一个带有 postgres。
这是我的docker-compose.yml
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build:
context: .
network: bridge
ports:
- "8081:8080"
depends_on:
- db
links:
- "db"
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
db:
image: "postgres"
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
但是当我尝试向我的端点之一发送请求时,什么也没有发生,直到最终我收到错误:读取 ECONNRESET
当然,当我 运行 我的应用程序在 docker 之外的电脑上时,我可以正常发送请求。我的设置有问题吗?
其他设置工作正常,但我想知道如何让两个容器像我的第一个 docker-compose 一样连接并能够从我的主机访问它们。
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build: .
depends_on:
- db
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
network_mode: host
db:
image: "postgres"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
network_mode: host
我终于明白了!
version: "3.8"
services:
web:
image: "time"
container_name: "time"
build: .
ports:
- "8080:8080"
depends_on:
- db
links:
- "db"
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
network_mode: bridge
db:
image: "postgres"
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: time
network_mode: bridge