编辑docker-compose.yml文件 定义四个服务(php nginx mysql redis) 四个服务使用同一个网络Inmp-net php依赖于mysql Nginx依赖于php和mysql Nginx需要定义端口号80:80娄数据挂载/nmp:/usr/share/nginx/html Php需要定义端口号9000:9090数据挂载/nmp:/www Mysql需要定义端口3306:3306 环境变量MYSQL_ROOT_PASSWORD=123456
时间: 2023-11-29 11:04:40 浏览: 103
可以按照以下的方式编辑docker-compose.yml文件:
version: '3'
services:
php:
image: php:latest
ports:
- "9000:9090"
volumes:
- "./nmp:/www"
networks:
- inmp-net
depends_on:
- mysql
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- "./nmp:/usr/share/nginx/html"
networks:
- inmp-net
depends_on:
- php
- mysql
mysql:
image: mysql:latest
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
networks:
- inmp-net
redis:
image: redis:latest
networks:
- inmp-net
networks:
inmp-net:
在这个docker-compose.yml文件中,我们定义了四个服务:php、nginx、mysql、redis。这四个服务都在同一个网络inmp-net中。
php服务依赖于mysql服务,因此我们在php服务中定义了depends_on属性。
nginx服务依赖于php和mysql服务,因此我们在nginx服务中定义了depends_on属性,并且定义了端口号80:80。
php服务需要定义端口号9000:9090,并且需要将本地的./nmp目录挂载到容器的/www目录中。
mysql服务需要定义端口号3306:3306,并且需要设置环境变量MYSQL_ROOT_PASSWORD为123456。
redis服务只需要加入到inmp-net网络中即可。
阅读全文
相关推荐












