Dockerfile
根目录下没有Dockerfile的可以复制下面的命令
# 使用基础镜像
FROM leekay0218/crmeb-mer
## 复制代码
## 在本地调试注释掉,使用映射把文件映射进去
#ADD ./ /var/www
# 设置工作目录
WORKDIR /var/www
# 设置时区为上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
echo '[PHP]\ndate.timezone = "'$TZ'"\n' > /usr/local/etc/php/conf.d/tzone.ini
# 创建 mer_s.conf 配置文件
RUN echo "[program:mer_s]" > /etc/supervisor/conf.d/mer_s.conf && \
echo "command=php think swoole restart" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "directory=/var/www/" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "autorestart=true" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "startsecs=3" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "startretries=3" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "stdout_logfile=/var/log/supervisor/mer_s.out.log" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "stderr_logfile=/var/log/supervisor/mer_s.err.log" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "stdout_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "stderr_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "user=root" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "priority=999" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "numprocs=1" >> /etc/supervisor/conf.d/mer_s.conf && \
echo "process_name=%(program_name)s_%(process_num)02d" >> /etc/supervisor/conf.d/mer_s.conf
# 创建 mer_q.conf 配置文件
RUN echo "[program:mer_q]" > /etc/supervisor/conf.d/mer_q.conf && \
echo "command=php think queue:work --tries 2" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "directory=/var/www/" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "autorestart=true" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "startsecs=3" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "startretries=3" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "stdout_logfile=/var/log/supervisor/mer_q.out.log" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "stderr_logfile=/var/log/supervisor/mer_q.err.log" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "stdout_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "stderr_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "user=root" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "priority=999" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "numprocs=1" >> /etc/supervisor/conf.d/mer_q.conf && \
echo "process_name=%(program_name)s_%(process_num)02d" >> /etc/supervisor/conf.d/mer_q.conf
# 设置入口命令
ENTRYPOINT ["/entrypoint.sh"]
# 创建日志文件
RUN touch /var/www/service.err.log /var/www/service.out.log
Docker镜像加速器
点击链接使用支付宝登录后就能看到加速器地址和操作方法
阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台
制作SWOOLE运行镜像
1. 进入到项目根目录看到Dockerfile文件后在当前目录打开命令行
执行命令,后面的点,一定不能缺少;创建一个叫:pro的镜像
镜像内php版本为7.4版本
docker build -t mer_test .
2. 运行镜像
docker run --name mer_test_con -itd -p 8324:8324 -v D:\crmeb\crmeb_merchant:/var/www mer_test
解释:
-v D:\crmeb\crmeb_merchant:/var/www 把本地D:\crmeb\crmeb_merchant下的文件映射到容器中的/var/www目录中这样就改了本地的文件容器内的就自动变
—name 容器名称
-p 20199:20199 映射端口
最后的参数:mer_test是镜像的名称
3. 进入容器查看
mer_test_con是上一步给容器设置的名称,其他都是固定格式
docker exec -it mer_test_con /bin/bash
# 查看supervisor管理里启动的程序
supervisorctl status
下面这样就是启动正常,如果mer_q(队列没有启动),检查一下redis是否连接正常
4 supervisor简单使用
序号 | 命令信息 | 作用说明 |
---|---|---|
1 | supervisorctl status | 产看所有进程状态 |
2 | supervisorctl stop [name] | 停止[name]服务 |
3 | supervisorctl start [name] | 启动[name]服务 |
4 | supervisorctl restart [name] | 重启[name]服务 |
5 | supervisorctl update | 重新加载配置文件 |
6 | supervisorctl reload | 重启配置中所有服务 |
把name换成all可以管理配置中的所有进程。
直接输入supervisorctl进入supervisorctl的shell交互界面,此时上面的命令不带supervisorctl可直接使用。
# 启动 supervisor
supervisord -c /etc/supervisor/supervisord.conf
5. 更多redis和mysql容器创建和使用
win10安装docker_swoole win10-CSDN博客