我们先来安装下php开发环境,lamp,lnmp,使用docker-compose编排工具,使用的过程中你自认知道他是什么。
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
cd ~/docker/mycompose vim docker-compose.yml
version: "3"
services:
fpm:
image: php:7.2.2-fpm-alpine
container_name: fpm
volumes:
- /home/longmore/www:/var/www
networks:
mywebnet:
ipv4_address: 192.158.0.2
httpd:
image: httpd:2.4.33-alpine
container_name: httpd
ports:
- "80:80"
volumes:
- /home/longmore/www:/usr/local/apache2/htdocs/
- /home/longmore/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf
networks:
mywebnet:
ipv4_address: 192.158.0.3
networks:
mywebnet:
driver: bridge
ipam:
config:
- subnet: 192.158.0.0/16
该配置文件设置了 fpm 的子网 ip 为 192.158.0.2,因此需要在 httpd.conf 配置中修改对应配置:
执行:
docker-compose [-p 指定名称] up -d
停止 docker-compose [-p 指定名称] stop
删除 docker-compose [-p 指定名称] rm
删除空闲网络 docker network prune
删除指定网络 docker network rm [network]
LNMP
docker-compose.yml
```yml
version: "3"
services:
fpm:
image: php:7.2.2-fpm-alpine
container_name: fpm
volumes:
- /home/longmore/www:/var/www
networks:
mynginx:
ipv4_address: 192.148.0.3
nginx:
image: nginx:1.15.1-alpine
container_name: nginx
ports:
- "80:80"