我有一个定义5个服务的docker-compose.yaml文件:
运行
docker-compose -f docker-compose.yaml up -d
命令导致:
Creating network "hlf_byfn" with the default driver
Creating peer1.org1.example.com ...
Creating peer0.org2.example.com ...
Creating peer1.org2.example.com ...
Creating orderer.example.com ...
Creating peer0.org1.example.com ...
Creating peer0.org2.example.com
Creating peer1.org1.example.com
Creating peer1.org2.example.com
Creating orderer.example.com
Creating orderer.example.com ... error
ERROR: for orderer.example.com Cannot create container for service orderer.example.com: Conflict. The container name "/orderer.example.com" is already in use by container "d6621116cf0d1ab108277893178ba29aCreating peer0.org1.example.com ... error
ERROR: for peer0.org1.example.com Cannot create container for service peer0.org1.example.com: Conflict. The container name "/peer0.org1.example.com" is already in use by container "185c6449d163fa5593001b3Creating peer0.org2.example.com ... done
ERROR: for peer0.org1.example.com Cannot create container for service peer0.org1.example.com: Conflict. The container name "/peer0.org1.example.com" is already in use by container "185c6449d163fa5593001b3bf9e052eee9ea365f89564a31fd84aac3c828bfbd". You have to remove (or rename) that container to be able to reuse that name.
ERROR: for orderer.example.com Cannot create container for service orderer.example.com: Conflict. The container name "/orderer.example.com" is already in use by container "d6621116cf0d1ab108277893178ba29a05d4e50b36143d33fb6ec1dfc472eeb8". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
无法创建 orderer.example.com 和 peer0.org1.example.com 。 输出 docker ps :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
543b2bf5df5c hyperledger/fabric-peer "peer node start" About a minute ago Up About a minute 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
1c652a838c3b hyperledger/fabric-peer "peer node start" About a minute ago Up About a minute 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
65bdfcf71517 hyperledger/fabric-peer "peer node start" About a minute ago Up About a minute 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
搬运工-compose.yaml:
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
networks:
byfn:
services:
orderer.example.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.example.com
container_name: orderer.example.com
networks:
- byfn
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
networks:
- byfn
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
networks:
- byfn
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
networks:
- byfn
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org2.example.com
networks:
- byfn
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artefacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artefacts
depends_on:
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
networks:
- byfn
我如何确定容器名称为何已经使用?
答案 0 :(得分:13)
根据您提供的错误:
错误:for orderer.example.com无法为服务orderer.example.com创建容器:冲突。容器名称" /orderer.example.com"已被容器使用" d6621116cf0d1ab108277893178ba29a创建peer0.org1.example.com ...错误
错误:对于peer0.org1.example.com无法为服务peer0.org1.example.com创建容器:冲突。容器名称" /peer0.org1.example.com"已被容器使用" 185c6449d163fa5593001b3创建peer0.org2.example.com ...已完成
错误:对于peer0.org1.example.com无法为服务peer0.org1.example.com创建容器:冲突。容器名称" /peer0.org1.example.com"已被容器使用 " 185c6449d163fa5593001b3bf9e052eee9ea365f89564a31fd84aac3c828bfbd&#34 ;.您必须删除(或重命名)该容器才能重用该名称。
错误:for orderer.example.com无法为服务orderer.example.com创建容器:冲突。容器名称" /orderer.example.com"已被容器使用" d6621116cf0d1ab108277893178ba29a05d4e50b36143d33fb6ec1dfc472eeb8"。您必须删除(或重命名)该容器才能重用该名称。
错误:启动项目时遇到错误
我假设你已经停止了从之前的执行/试验中删除/清理过的容器,因此启动具有相同名称的新容器会导致上述错误。你能不能试试
docker ps -a
检查是否有容器名称为peer0.org1.example.com
,peer0.org1.example.com
等等?
无论如何,您可以尝试运行
docker ps -qa | xargs docker rm
然后再次尝试启动您的网络:
docker-compose -f docker-compose.yaml up -d
答案 1 :(得分:0)
您需要停止容器
docker ps -qa | xargs docker stop
答案 2 :(得分:0)
该示例用于存储库的FirstNetwork示例:
这对我有用: 清理环境:
docker ps -aq
^这将为您提供容器ID的列表。 一张一张地删除它们:
docker rm -rf containerIds
执行向下命令:
./ byfn.sh -m down
然后执行向上命令:
./ byfn.sh -m up