當我嘗試建置時,為什麼會創建 moby/buildkit:buildx-stable-1 並導致容器名稱衝突?

當我嘗試建置時,為什麼會創建 moby/buildkit:buildx-stable-1 並導致容器名稱衝突?

我有以下 docker-compose...

version: "3.8"
services:
  proxy:
    container_name: proxy
    extra_hosts:
      - "host.docker.internal:host-gateway"
    build:
      context: proxy
      dockerfile: Dockerfile
    volumes:
      - ./proxy/certificate:/usr/cert
    ports:
      - "443:443"
  ui:
    container_name: ui
    restart: always
    build:
      context: frontend
    ports:
      - "80:80"
  backend:
    container_name: backend
    restart: always
    build:
      context: backend
    ports:
      - "8000:8000"
    environment:
      - API_KEY
      - GOLD_TOKEN

然後我使用以下 shell 腳本來建置...

#! /bin/bash
docker-compose build
docker-compose up -d

但是當我運行 shell 腳本時,它會嘗試建立一個moby/buildkit:buildx-stable-1容器。該容器失敗,我最終在建置中出現以下錯誤...

 => ERROR [internal] booting buildkit                                                                                                                                  0.9s
 => => pulling image moby/buildkit:buildx-stable-1                                                                                                                     0.8s
 => => creating container buildx_buildkit_gallant_newton0                                                                                                              0.1s
[+] Building 0.9s (1/1) FINISHED                                                                                                                                            
 => CANCELED [internal] booting buildkit                                                                                                                               0.9s
 => => pulling image moby/buildkit:buildx-stable-1                                                                                                                     0.8s
 => => creating container buildx_buildkit_gallant_newton0  
Error response from daemon: Conflict. The container name "/buildx_buildkit_gallant_newton0" is already in use by container "8b56bc95c1e26b736d0f297236adce9766f1363b1f94b35fcbc29ac96b4b61d3". You have to remove (or rename) that container to be able to reuse that name.

為什麼會發生這種情況以及如何防止這種衝突?

答案1

該容器顯然是由 Docker BuildKit(新的docker build替代品)使用以下映像創建的: https://hub.docker.com/r/moby/buildkit

若要停用此容器,您可以將建構器實例設定為預設值:

docker buildx use default

相關內容