Cannot create container for service peer1.org2.example.com: Conflict. 解决方案

本文解决了一个关于 Docker Compose 在启动多个服务容器时遇到的名称冲突问题,详细分析了错误日志并提供了清理旧容器的方法,以便重新启动服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have a docker-compose.yaml file defining 5 services:
  • orderer.example.com
  • peer0.org1.example.com
  • peer1.org1.example.com
  • peer0.org2.example.com
  • peer1.org2.example.com

Running the

docker-compose -f docker-compose.yaml up -d

command results in:

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.

So orderer.example.com and peer0.org1.example.com could not be created. Output of 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

docker-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

How can I determine, what went wrong, why the container name is in use already?

  •  
    Can you please paste your docker-compose.yaml file? 
  • added docker-compose.yaml – 

Based on the errors you provided:

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

I'd assume that you have stopped containers which was not removed/cleaned up from your previous executions/trials and therefore starting new containers with same names concludes to the errors above. Could you please try to run

docker ps -a

  

to check whenever you have containers with names: peer0.org1.example.compeer0.org1.example.com and etc...?

At any case you can try to run

docker ps -qa | xargs docker stop

  

docker ps -qa | xargs docker rm

  

and then try to startup your network again:

docker-compose -f docker-compose.yaml up -d

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值