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

Docker容器测试Hyperledger Sawtooth Validator连通性遇域名解析错误

Hey there, let's tackle this "could not resolve host rest-api" issue you're hitting when testing your Hyperledger Sawtooth setup. This is almost always a DNS/network connectivity problem between your client container and the rest-api service. Here's how to fix it step by step:

1. Verify your containers are on the same Docker network

Docker containers can only resolve each other's service names if they're connected to the same network. Let's check that first:

  • List all existing Docker networks: docker network ls
  • Check which network your rest-api container is using: docker inspect <rest-api-container-name> | grep Networks
  • Check which network your client container is using: docker inspect <client-container-name> | grep Networks
    If they're on different networks, connect the client container to the rest-api's network with: docker network connect <target-network-name> <client-container-name>
2. Confirm the rest-api service name matches your curl command

If you're using Docker Compose to deploy Sawtooth, double-check your docker-compose.yml file. The service name for the REST API might not be exactly rest-api—sometimes it's named sawtooth-rest-api or something similar. If that's the case, update your curl command to use the correct service name, e.g.:
curl http://sawtooth-rest-api:8008/blocks

3. Test with the rest-api container's direct IP

If DNS resolution is still failing, bypass it entirely by using the rest-api container's IP address to confirm connectivity:

  • Get the rest-api container's IP: docker inspect <rest-api-container-name> | grep "IPAddress"
  • Run this command inside your client container: curl http://<rest-api-ip>:8008/blocks
    If this works, you know the issue is strictly with DNS resolution, not basic connectivity.
4. Manually add a host mapping to the client container

If the network is correct but DNS still won't resolve, you can manually map the rest-api hostname to its IP in the client container's hosts file:

  • Enter the client container: docker exec -it <client-container-name> /bin/bash
  • Add the mapping: echo "<rest-api-ip> rest-api" >> /etc/hosts
    Now retry your original curl command—it should resolve the hostname successfully.
5. Ensure your client container uses the Docker Compose network

If you started the rest-api via Docker Compose but launched the client container manually, the client is probably on Docker's default bridge network instead of the Compose-specific user-defined network. Compose networks automatically handle DNS for service names, so start your client container with the --network flag pointing to the Compose network:
docker run -it --network <docker-compose-network-name> <client-image> /bin/bash

Once you've worked through these steps, your curl command should connect to the validator without issues. Feel free to ask if you need help with any specific step!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:05:23