You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac OS+Docker 19环境下Postman无法访问Docker容器的求助

Troubleshooting Access to Your client-service Container on Docker 19 for Mac

Let’s break down how to get your container accessible step by step—this is a common gotcha with bridge networks and Spring Boot apps in Docker!

First, Verify the Basics

Start by ruling out simple issues that might be blocking access:

  • Check if the container is actually running:
    Run docker-compose ps and confirm client-service shows a state of Up. If it’s Exited or Restarting, there’s a problem with the service itself.
  • Inspect container logs for startup errors:
    Run docker-compose logs -f client-service to stream real-time logs. Look for:
    • Confirmation that Spring Boot started successfully (e.g., Started ClientServiceApplication in X seconds)
    • Errors connecting to Cassandra (since depends_on only waits for Cassandra to start, not to be ready—your app might fail if Cassandra isn’t fully initialized)
  • Test access inside the container:
    Run docker exec -it client-service curl http://localhost:8087. If this fails, your service isn’t running properly inside the container—fix that first before troubleshooting external access.

Fix the Most Likely Culprit: Spring Boot Listening on 127.0.0.1

By default, some Spring Boot apps are configured to listen only on 127.0.0.1 (loopback inside the container). This means the service won’t respond to requests from outside the container, even with port mapping enabled.

  • Update your application-dev.yml (or application.properties) to force the service to listen on all interfaces:
    server:
      address: 0.0.0.0
      port: 8087
    
  • Rebuild your Docker image with the updated config: docker build -t client-service .
  • Restart the container: docker-compose down && docker-compose up -d

Validate Port Mapping and Network Setup

  • Check if the port is properly exposed:
    Run docker port client-service—you should see output like 8087/tcp -> 0.0.0.0:8087. This confirms the port is mapped to all interfaces on your Mac.
  • Remove conflicting /etc/hosts entry:
    You added 127.0.0.1 host.docker.local, but Docker 19 for Mac already configures host.docker.internal to point to the host machine. Delete that custom entry to avoid conflicts.
  • Test alternative access methods:
    • Try http://localhost:8087 first (this should work if port mapping is correct and the service is listening on 0.0.0.0)
    • If localhost fails, test with Docker’s internal bridge IP: Run ifconfig docker0 to get the IP (usually something like 172.17.0.1), then visit http://172.17.0.1:8087
    • Check your Mac’s firewall—temporarily disable it to rule out port blocking.

Handle Cassandra Readiness Issues

Since your app depends on Cassandra, it might crash or fail to start if Cassandra isn’t fully ready when the app boots. Add a health check to your docker-compose.yml to ensure the app only starts accepting traffic once it’s healthy:

client-service:
  # ... your existing config
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:8087/actuator/health"]
    interval: 30s
    timeout: 10s
    retries: 3

Note: This requires adding the Spring Boot Actuator dependency to your project.

内容的提问来源于stack exchange,提问作者prostý člověk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 07:32:30