docker-compose报错:Conflict. The container name is already in use by container
报错表现:
- 在docker-compose启动容器的时候,报错
The container name is already in use by container
- 根据容器名称查询,
docker ps -a | grep [容器名称],找不到该容器
- 根据容器ID查询,
docker ps -a | grep [容器ID],可以看到该容器,并且该容器hang在Created状态
可能的解决方案:
docker-compose.yml文件中,service名称与container_name一致,可能会导致该问题,如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| version: '3' services: activemq: image: webcenter/activemq deploy: resources: limits: cpus: '1' memory: 2G reservations: cpus: '1' memory: 2G container_name: activemq restart: always environment: ACTIVEMQ_CONFIG_MINMEMORY: "512" ACTIVEMQ_CONFIG_MAXMEMORY: "2048" ports: - "8161:8161" - "61616:61616" volumes: - /data/activemq:/data
|
把 container_name: activemq 这一行删除掉,运行docker compose down && docker compose up -d重新启动即可。