数据库使用两个别名 db mysql
docker network create -d bridge my-bridge-network # 创建一个网络
docker run -itd --name mariadb --env MYSQL_ROOT_PASSWORD=example \
--network=my-bridge-network --network-alias=db --network-alias=mysql mariadb # 启动数据库
docker run -itd --name MyWordPress --network=my-bridge-network --network-alias=lap -p 80:80 wordpress # 启动应用
docker run --name db --env MYSQL_ROOT_PASSWORD=example -d mariadb 启动数据
docker run --name MyWordPress --link db:mysql -p : -d wordpress 启动 LAP
使用网络
version: ''
services:
web:
image: http
networks:
- myappnet1
worker:
image: http
networks:
- myappnet2
db:
image: http
networks:
myappnet1:
aliases:
- database
myappnet2:
aliases:
- mysql
networks:
myappnet1:
myappnet2:
version: ''
services:
web:
image: http
container_name: web
depends_on:
version: ''
services:
web:
image: lap
container_name: web
restart: always
depends_on:
- db
ports:
- "80:80"
networks:
- mynet
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/www:/var/www
db:
image: mariadb
container_name: db
restart: always
networks:
mynet:
aliases:
- mysql
- db
- database
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/mysql/data:/var/lib/mysql
networks:
mynet:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章