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

Windows 10下Docker运行Elasticsearch失败:端口无法访问求助

Troubleshooting: Can't Access Elasticsearch Ports 9200/9300 on Windows 10 After docker-compose up

Alright, let's figure out why you can't hit those 9200/9300 ports after running docker-compose up on your Windows 10 machine. Here's what to check and fix step by step:

1. First: Is your myapp service actually running Elasticsearch?

Looking at your docker-compose.yml, you're building a custom myapp service from a local Dockerfile—but you mentioned you're trying to start Elasticsearch. If that Dockerfile doesn't use an Elasticsearch base image (like FROM elasticsearch:7.x or FROM docker.elastic.co/elasticsearch/elasticsearch:8.x), then your container isn't running Elasticsearch at all. No wonder the ports are unresponsive!

  • Open up ./docker/Dockerfile and check its first line. If it's not pulling an Elasticsearch image, you'll need to adjust the Dockerfile to build on top of one, or swap out the custom build for the official Elasticsearch image directly in your compose file.

2. Verify your container is actually running

Even if your Dockerfile is correct, containers can fail silently. Let's confirm status:

  • Run docker ps in your terminal. If myapp shows up as Exited or Restarting, it crashed on startup.
  • Grab the container logs to find the root cause: docker logs myapp. Common issues here include insufficient memory (Elasticsearch needs a decent amount) or misconfigured Elasticsearch settings.
  • Double-check Windows Defender Firewall: Sometimes it blocks traffic to Docker's mapped ports. Try temporarily disabling it to test, or add a rule allowing inbound/outbound traffic on 9200 and 9300 for the docker-proxy process.

3. Fix your docker-compose config (for quick Elasticsearch setup)

If your goal is just to get Elasticsearch running, skip the custom build for now and use the official image. Here's an adjusted version of your config that should work:

version: "2"
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10 # Pick a compatible version
    container_name: elasticsearch
    hostname: elasticsearch
    volumes:
      - ../data:/usr/share/elasticsearch/data # Specify the exact mount path for persistence
    networks:
      - app-test
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - discovery.type=single-node # Required for single-node test setup
      - ES_JAVA_OPTS=-Xms512m -Xmx512m # Tune memory to avoid crashes on Windows
      - ES_CONNECT_RETRY=120
      - network.host=0.0.0.0 # Ensure Elasticsearch binds to all interfaces
networks:
  app-test:
    driver: bridge

4. Test access the right way

On Windows, localhost:9200 can sometimes have network quirks with Docker Desktop. Try accessing via the container's direct IP:

  • Get the container IP with: docker inspect myapp | findstr "IPAddress"
  • Visit http://<container-ip>:9200 in your browser or use curl <container-ip>:9200 in PowerShell.

内容的提问来源于stack exchange,提问作者user1883212

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:07:03