gpt4 book ai didi

docker - 相同的docker配置与不同项目重复

转载 作者:行者123 更新时间:2023-12-02 19:00:06 25 4
gpt4 key购买 nike

我有两个具有相同docker配置(docker-compose.yml),但文件不同的不同项目。

├── a
│ ├── docker-compose.yml
│ └── Dockerfile
└── b
├── docker-compose.yml
└── Dockerfile

如何为不同的项目构建具有相同名称的容器?如果我仅同时在一个项目上工作,我不想为每个项目想到新名称。
ERROR: for mysql  Cannot create container for service mysql: Conflict. The container name "/mysql" is already in use by container "90a84268d483ec2bd5cf0feb7ab1972384941ba255a671c0cfd2b4017ce90682". You have to remove (or rename) that container to be able to reuse that name.

Docker-compose.yml
version: '3'

services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel

mysql:
image: mysql:8.0.19
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel

php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel

最佳答案

不要覆盖container_name

关于docker - 相同的docker配置与不同项目重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61275714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com