Docker部署Hyperledger Sawtooth后测试XO交易连接失败求助
Looks like you're hitting a common Docker networking snag here. When you run xo create one inside the sawtooth-shell-default container, it’s trying to connect to 127.0.0.1:8008—but that points to the localhost of the shell container itself, not your host machine or the Sawtooth REST API container where the service actually runs.
Why This Happens
Each Docker container has its own isolated network namespace. The Sawtooth REST API runs in a separate container (usually named sawtooth-rest-api-default), so the shell container can’t reach it via 127.0.0.1. Docker’s internal DNS resolves container names to their respective IPs within the shared network, so we need to use that instead.
Step-by-Step Fix
Here’s how to get your XO transaction working:
Verify the REST API container is running
From your host machine, list active containers to confirm the REST API container is up:docker psYou should see
sawtooth-rest-api-defaultin the output. If not, start it with:docker start sawtooth-rest-api-defaultUpdate the REST API URL in the shell container
Once you’re insidesawtooth-shell-default, set theSAWTOOTH_REST_API_URLenvironment variable to point to the REST API container’s name:export SAWTOOTH_REST_API_URL=http://sawtooth-rest-api-default:8008Retry the XO transaction
Now run your command again:xo create oneThis should successfully connect to the REST API and submit your transaction.
Extra Checks
- Ensure all Sawtooth containers are on the same Docker network. By default, they use
sawtooth_default. Verify this with:
Check that bothdocker network inspect sawtooth_defaultsawtooth-shell-defaultandsawtooth-rest-api-defaultare listed under the "Containers" section.
内容的提问来源于stack exchange,提问作者XYZVoyager

