能否在Hyperledger Composer-Playground容器内启动REST Server及问题咨询
Great question! Let's tackle this from three key angles: whether you can run the Composer REST Server inside the playground container, fixing that Python error you hit, and how to interact with your business network once it's set up.
Absolutely — but you'll need to address missing dependencies first (like the Python issue you encountered) since the base playground container doesn't come with all tools pre-installed. Let's walk through fixing that error first.
This error pops up because some npm packages (including parts of composer-rest-server) expect a python executable in the PATH, but the playground container doesn't have Python installed by default. Here's how to fix it:
First, access the running container's shell:
Run this command on your host machine (replace<container-id/name>with your playground container's ID or name — you can get this viadocker ps):docker exec -it <container-id/name> /bin/bashInstall Python and link it to the
pythonalias:
The container is based on Ubuntu, so we can use apt to install Python 3 and set it as the defaultpythonexecutable:apt-get update && apt-get install -y python-is-python3This package creates a symlink from
pythontopython3, which satisfies the npm package's requirement.Install the Composer REST Server:
Now you can install the server globally without errors:npm install -g composer-rest-server
Once the REST Server is installed, you have two main ways to interact with your business network:
1. Run the REST Server inside the container (with port mapping)
If you haven't started the container yet: Launch it with port 3000 (the default REST Server port) mapped to your host:
docker run -p 8080:8080 -p 3000:3000 hyperledger/composer-playground(Port 8080 is for the playground UI, 3000 is for the REST Server.)
If the container is already running: After installing the REST Server inside, start it with:
composer-rest-server -c admin@<your-business-network-name> -n never -w true-c: Specifies the connection profile for your business network (use the same name you used when deploying the network in the playground).-n never: Disables TLS (safe for testing environments).-w true: Allows anonymous access to the REST API (again, for testing — restrict this in production).
You can now access the REST API from your host machine at
http://localhost:3000, and use the Swagger UI to test endpoints or connect your application to it.
2. Persist your setup (avoid re-installing on container restart)
Since Docker containers are ephemeral, any changes (like installing Python or the REST Server) will be lost when the container stops. To avoid redoing this every time, create a custom Docker image:
Create a
Dockerfilewith:FROM hyperledger/composer-playground RUN apt-get update && apt-get install -y python-is-python3 RUN npm install -g composer-rest-serverBuild the image:
docker build -t my-composer-playground .Run your custom image with port mapping:
docker run -p 8080:8080 -p 3000:3000 my-composer-playground
Now every time you start the container, the REST Server and Python will already be installed and ready to use.
内容的提问来源于stack exchange,提问作者Bharath

