正式环境docker部署hyperf_Hyperf使用docker-compose集群部署

从运行容器开始

docker run -v /www:/www -p 9601:9601 -p 9602:9602 -p 9603:9603 -it --entrypoint /bin/sh hyperf/hyperf:latest

# 镜像容器运行后,在容器内安装 Composer

wget https://github.com/composer/composer/releases/download/1.8.6/composer.phar

chmod u+x composer.phar

mv composer.phar /usr/local/bin/composer

# 将 Composer 镜像设置为阿里云镜像,加速国内下载速度

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

$ cd /www

# 通过 Composer 安装 hyperf/hyperf-skeleton 项目

composer create-project hyperf/hyperf-skeleton api

composer create-project hyperf/hyperf-skeleton org

composer create-project hyperf/hyperf-skeleton mms

在每个项目根目录里面都安装watch,这是热加载组件

wget -O watch https://gitee.com/hanicc/hyperf-watch/raw/master/watch

使用docker-compose启动

1、在宿主机的www目录下创建一个docker-compose目录,该目录用于存放相关的docker-compose和dockerfile文件

ps:这里不一定要在www目录下,但是换了其他目录的时候执行docker—compose -f 后面要带路径

2、在docker-compose目录下分别创建三个文件夹api、org、mms,这三个文件夹存储对应项目的dockerfile,内容如下:

FROM hyperf/hyperf

WORKDIR /www

#CMD ["php","bin/hyperf.php","start"]

CMD php watch -c

因为使用的都是同个镜像,所以内容都一样

3、边写docker-compose.yml

version: '2'

networks:

dev_yes:

services:

api:

build:

context: ./api

dockerfile: dockerfile

ports:

- "9601:9601"

volumes:

- /www/api:/www

networks:

- dev_yes

mms:

build:

context: ./mms

dockerfile: dockerfile

ports:

- "9602:9602"

你可能感兴趣的:(正式环境docker部署hyperf_Hyperf使用docker-compose集群部署)