首页 > 解决方案 > Docker Setup, cannot clone the repository because container name already taken

问题描述

I am really new to Docker and am trying to set it up on my laptop. I am on the "Getting Started" project and am trying to clone the repository, but when I run the code it says Error: No such container:path: repo:/git/getting-started/

It also says Error response from daemon: Conflict.T The container name "/repo" is already in use by container "23b79....."

I tried to use File Explorer to find a folder named "repo" but could not find anything. I am also not sure how to search for that container since it just gives me a large string.

Here is a screenshot of what it shows on Docker for me.

标签: dockerubuntu

解决方案


当具有相同名称的容器不再运行时,可能会发生此故障。您的第二个命令docker cp repo:/git/getting-started/ .失败,因为repo在上一步中未正确创建容器。

Containers/Apps您可以在 Docker 桌面页面上查看正在运行的容器。下面显示了csci104从 repo 命名和标记的容器usccsci104/docker:20.04正在运行:

Docker 桌面容器和应用程序页面截图

或者,您可以使用docs heredocker ps命令检查正在运行的容器。

我建议您尝试使用docker system prune命令清除未使用的容器或显式删除repo容器,以便您重试:

# this will clear all unused containers you have created
docker system prune -f

# this will remove the /repo container causing docker run command to fail
docker rm -f repo

然后,重试运行该docker run命令,如果成功,则重试该docker cp命令。


推荐阅读