为什么当我尝试构建时会创建 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

相关内容