一、下载容器
docker-compose中可以直接下载,一般我喜欢先下载容器
docker pull duqiudong277/php-fpm:5.4
docker pull httpd:2.4-alpine
二、docker-compose配置
version: '2'
services:
php:
image: duqiudong277/php-fpm:5.4
container_name: php54
ports:
- "9000:9000"
expose:
- 9000
volumes:
- /Users/duqiudong/Documents/php/fw-admin:/var/www/html
- ../../conf/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
stdin_open: true
tty: true
networks:
- "mynet"
apache2:
image: httpd:2.4-alpine
container_name: httpd
volumes:
- ../../conf/apache/site:/usr/local/apache2/sites-enabled
- /Users/duqiudong/Documents/php/fw-admin:/var/www/html
- ../../logs/httpd:/var/log/httpd
- ../../conf/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
ports:
- "8088:80"
- "80:80"
links:
- php
networks:
- "mynet"
networks:
mynet:
external: true
三、docker-compose中的文件配置
1.www.conf
docker cp 容器:/usr/local/etc/php-fpm.d/www.conf ./
将代码 listen:127.0.0.0:9000 改为 0.0.0.0:9000
2.httpd.conf
docker cp 容器:/usr/local/apache2/conf/httpd.conf ./
新建sites-enabled目录,作为vhost文件目录
在http.conf中放入include包含该文件下所有的conf后缀
Include sites-enabled/*.conf
www.conf + httpd.conf 解析php配置参考:https://blog.csdn.net/agave7/article/details/97242400
3.配置修改
执行
docker-compose up -d
php 使用mysql容器名称链接
1、 创建一个网络:
docker network create mynet
2、将mysql加入这个网络中:
docker network connect mynet mysql
3、在业务中连接host可填写如下
mysql:3306
参考文档:https://docs.docker.com/engine/reference/commandline/network_connect/