Dockerfile启动php服务注册apollo的容器

avatar 2021年9月6日18:28:56 评论 450 次浏览

前面做了一个php的dockerfile。这里把这个服务在kubenetes中启动起来,我们需要在原有的镜像拉取后把代码copy到容器中,然后启动容器后在启用apollo和php-fpm,最后在启动nginx服务。这样的好处是能够在健康检查之前,把本地的服务注册信息可以拉取过来。然后启动,对外提供服务等等。

php_star="/usr/sbin/php-fpm"
nginx_star='/usr/local/nginx/sbin/nginx -g "daemon off;"'
apollo_start="php /usr/local/nginx/html/apollo-php-client/apollo.php   >/dev/null 2>&1 &"
apollo='`ps -ef |grep -w apollo|grep -v grep|wc -l`'
echo -e "
#!/bin/bash
while true
do
    if [ ${apollo} -le 0 ];then
        echo "testPro is not run"
        sh /usr/local/nginx/html/apollo-php-client/start.sh
    else
        break 
    fi 
done
${php_star}
${nginx_star} " > enpoint.sh
cat << EOF > Dockerfile
FROM .aliyuncs.com/reatil-harb/web-image-service:1.0
COPY  . /usr/local/nginx/html/
RUN chown -R www:www /usr/local/nginx/html/
WORKDIR /usr/local/nginx/html/apollo-php-client
RUN rm -rf vendor
RUN composer require multilinguals/apollo-client --ignore-platform-reqs
RUN chmod +x start.sh
EXPOSE 80
EXPOSE 443
EXPOSE 9000
COPY enpoint.sh /usr/sbin/enpoint
RUN chmod +x /usr/sbin/enpoint
CMD  ["/bin/bash","enpoint"]
EOF

上面是启动脚本,因为apollo做了一个循环,这里的循环是为了确定apollo能够获取到信息,终止循环,最后是启动php-fpm和nginx服务,把这个脚本copy到容器后,直接启动脚本即可,这里需要注意的是启动顺序,如果先启动nginx就会出现用户请求过来了,但是服务还没有拉取到apollo的信息,造成用户请求不可用。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: