我想在同一台服务器上为多个项目使用一个MySQL Docker容器。
使用docker-compose v3文件,我只需在每个项目中具有相同的mysql容器配置,并且它们具有相同的container_name
:
version: "3"
services:
app1:
image: foo
links:
- mysql
mysql:
image: mysql/mysql:5.7
container_name: shared_mysql
第二个应用程序有一个类似的docker-compose.yml
文件,但是使用app2
而不是app1
。
在运行docker-compose up --no-recreate
命令来启动app2
时,我遇到了一个错误:
Creating shared_mysql ... error
ERROR: for shared_mysql
Cannot create container for service mysql: Conflict.
The container name "/shared_mysql" is already in use by container "deadbeef".
You have to remove (or rename) that container to be able to reuse that name.
我该如何在多个Docker项目之间共享MySQL容器?