root@192 lib # docker run -d --name InStockDbService \ -v…
- User
User: root@192 lib # docker run -d --name InStockDbService
-v /data/mariadb/data:/var/lib/instockdb
-e MYSQL_ROOT_PASSWORD=root
library/mariadb:latest docker: Error response from daemon: Conflict. The container name "/InStockDbService" is already in use by container "bf2e059135e9d5243d0e044cbe7d1752720b6e3a973b00f714d2de54e3dfaa32". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'. Assistant: This error means you already have a Docker container running with the nameInStockDbService. The Docker daemon won't let you create a new container with the same name.Here's how to fix it:
1. Identify the existing container:
First, you need to find the ID of the running container. Use this command:
bashdocker psThis will list all running containers. Look for one with the name
InStockDbService. The output will show the container ID (a long string of characters likebf2e059135e9d5243d0e044cbe7d1752720b6e3a973b00f714d2de54e3dfaa32in your error message).2. Stop and remove the existing container:
Once you've identified the container ID (let's call it
CONTAINER_ID), use these commands:bashdocker stop CONTAINER_ID docker rm CONTAINER_IDReplace
CONTAINER_IDwith the actual ID from thedocker psoutput.docker stop CONTAINER_IDgracefully stops the container.docker rm CONTAINER_IDremoves the stopped container.
3. Run your new container:
After stopping and removing the old container, you can now run your new
InStockDbServicecontainer using the original command:bashdocker run -d --name InStockDbService \ -v /data/mariadb/data:/var/lib/instockdb \ -e MYSQL_ROOT_PASSWORD=root \ library/mariadb:latestImportant Considerations:
- Data Persistence: The
-v /data/mariadb/data:/var/lib/instockdbvolume mount is crucial for persistent data. Make sure the/data/mariadb/datadirectory exists on your host machine before running the container. If you remove the container, the data in will remain. If you want to start fresh, delete the contents of that directory before running the new container.
- Assistant
如果你在 Docker Desktop 中没有找到 "Preferences" 设置,请按照以下步骤操作:
-
打开 Docker Desktop: 首先,确保你已经启动了 Docker Desktop 应用程序。
-
访问设置:
- 在 Docker Desktop 主界面上,通常左上角会有一个 Docker 图标,点击它。
- 或者,如果你在 Mac 的菜单栏中看到 Docker 图标(鲸鱼图标),可以直接点击该图标。
-
查找 Preferences 或 Settings:
- 在下拉菜单中,寻找 "Preferences" 或 "Settings"(设置)选项。这个选项在不同版本的 Docker 中可能稍有不同,但通常是在菜单的顶部。
-
找到 Resources 部分:
- 打开 "Preferences" 后,在左侧面板中找 "Resources" 部分。
- 点击 "File Sharing" 选项。
-
添加共享路径:
- 在 "File Sharing" 窗口中,点击 "+" 按钮添加新的路径。
- 输入或选择你的路径
/data/mariadb/data。 - 然后确认保存这些更改。
-
重启 Docker: 更改文件共享设置后,建议重启 Docker Desktop 以确保设置生效。
完成这些步骤后,你再尝试运行你的 Docker 命令,应该能够成功挂载该目录。如果仍然遇到问题,请确保路径
/data/mariadb/data在你的文件系统中确实存在。 -