微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

DOCKERFILE:运行多个CMD. (启动NGINX和PHP)

参见英文答案 > Why can’t I use Docker CMD multiple times to run multiple services?                                    3个
我有一个dockerfile设置Nginx,PHP,添加一个wordpress存储库.我想在启动时启动PHPNginx.但是,我没有这样做.我尝试在CMD数组中添加两个命令,我也尝试将它们放在shell文件中并启动shell文件.没有任何效果.下面是我的Dockerfile

FROM ubuntu:16.04

workdir /opt/

#Install Nginx
RUN apt-get update
RUN apt-get install -y Nginx=1.10.* PHP7.0 PHP7.0-fpm PHP7.0-MysqL

#Add the customized Nginx configuration
RUN rm -f /etc/Nginx/Nginx.conf
RUN rm -f /etc/Nginx/sites-enabled/*

copY Nginx/Nginx.conf /etc/Nginx/
copY Nginx/site.conf /etc/Nginx/sites-enabled

#copy the certificates
RUN mkdir -p /etc/pki/Nginx
copY Nginx/certs/* /etc/pki/Nginx/
RUN rm -f /etc/pki/Nginx/placeholder

#copy the build to its destination on the server
RUN mkdir -p /mnt/wordpress-blog/
copY . /mnt/wordpress-blog/

#copY wp-config.php
copY Nginx/wp-config.php /mnt/wordpress-blog/

#The command to run the container
CMD ["/bin/bash", "-c", "service PHP7.0-fpm start", "service Nginx start"]

我试图将命令放在CMD中的shell文件中,然后在CMD命令中运行shell文件.它仍然无法正常工作.我错过了什么?

解决方法:

start.sh

#!/bin/bash

/usr/sbin/service PHP7.0-fpm start
/usr/sbin/service Nginx start
tail -f /dev/null

Dockerfile

copY ["start.sh", "/root/start.sh"]
workdir /root
CMD ["./start.sh"]

有了这个,你可以在start.sh中放入更复杂的逻辑.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐