直到出现新版本的php或mysql时,我通常总是使用相同的设置,所以目前我为我创建的每个站点创建3个容器:-
网站1:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site1
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site1
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site1
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site1
networks:
site1:
volumes:
db_data:
网站2:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site2
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site2
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site2
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site2
networks:
site2:
volumes:
db_data:
除了网络之外,它们是相同的,但这意味着我实际上仅需要3个容器时,我有6个容器。是否可以告诉站点2使用站点1创建的服务,或者这是否与docker的全部内容背道而驰?
所以我要更改:-
站点1使用php,mysql和phpmyadmin。站点2使用php1,mysql1,phpmyadmin1。
收件人:
站点1和站点2使用相同的容器,但是具有自己的数据库:-
站点1使用php,mysql(数据库site1)和phpmyadmin。站点2使用php,mysql(数据库site2)和phpmyadmin