You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Hyperledger Fabric环境下CouchDB Docker镜像向本地CouchDB复制失败但反向复制正常问题求助

Fixing CouchDB Replication from WSL2 Docker Container to Local Windows Instance

Hey there, let's work through this replication issue you're facing. It's odd that you can push data from your local Windows CouchDB to the WSL2 Docker container, but not pull it the other way around—this usually boils down to network access or permission configurations. Here's a step-by-step breakdown of the most likely fixes:

1. Ensure Your Windows CouchDB is Accessible from WSL2

By default, CouchDB on Windows binds to 127.0.0.1, which means it only accepts connections from the local Windows machine. WSL2 and Docker containers run in their own virtual network, so they can't reach 127.0.0.1 on Windows.

  • Open your Windows CouchDB config file (typically located at C:\Program Files\Apache\CouchDB\etc\couchdb\local.ini).
  • Find the bind_address setting under the [chttpd] section, and change it from 127.0.0.1 to 0.0.0.0 (this allows connections from any IP).
  • Restart the CouchDB service on Windows (you can do this via Services.msc or the command line).
  • Test connectivity from WSL2: Run curl http://<YOUR_WINDOWS_HOST_IP>:5984/_all_dbs in your WSL2 terminal. Replace <YOUR_WINDOWS_HOST_IP> with the IPv4 address of your Windows machine (find this via ipconfig in a Windows Command Prompt). If you get a list of databases back, the network path is open.

2. Enable CORS on Your Windows CouchDB

CouchDB replication relies on cross-origin requests, and if CORS isn't configured correctly, the replication from Docker to Windows will fail silently.

  • Open the CouchDB Fauxton interface on Windows: http://localhost:5984/_utils.
  • Navigate to Settings > CORS.
  • Toggle "Enable CORS" to on, set "Origin" to * (or restrict it to your WSL2 subnet for security), check all allowed methods, and save the changes.

3. Adjust Docker Container Network Mode

By default, Docker containers in WSL2 use a bridged network, which can create barriers to accessing the Windows host. Switching to host network mode lets the container share the WSL2 network stack, making it easier to reach your Windows CouchDB.

  • In your Hyperledger Fabric docker-compose.yml file, modify the CouchDB service definition to include network_mode: host:
    couchdb:
      image: couchdb:latest
      network_mode: host
      environment:
        - COUCHDB_USER=admin
        - COUCHDB_PASSWORD=adminpw
      # Keep your other volume/port configurations if needed (note: ports aren't required with host mode)
    
  • Restart the CouchDB container with docker-compose up -d couchdb.

4. Verify Replication Target URL

When setting up replication from the Docker CouchDB to Windows, make sure you're using the correct target URL. Using localhost:5984 inside the Docker container will point to the container itself, not your Windows machine.

  • Use your Windows host IP instead, e.g., http://<YOUR_WINDOWS_HOST_IP>:5984/target_db.
  • You can test this from inside the Docker container: Run docker exec -it <YOUR_COUCHDB_CONTAINER_NAME> bash, then execute curl http://<YOUR_WINDOWS_HOST_IP>:5984/_all_dbs to confirm access.

5. Check Windows Firewall Rules

Windows Firewall might be blocking incoming connections from WSL2 or Docker to port 5984.

  • Open Windows Defender Firewall > Advanced Settings > Inbound Rules.
  • Create a new rule:
    • Rule Type: Port
    • Protocol and Ports: TCP, Specific local ports: 5984
    • Action: Allow the connection
    • Profile: Check Domain, Private, and Public (adjust based on your network)
    • Name: "Allow CouchDB from WSL2/Docker"

Start with the network accessibility checks first—those are the most common culprits here. Once you confirm the Docker container can reach your Windows CouchDB, the replication should work as expected.

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

火山引擎 最新活动