Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOCKERFILE: Running multiple CMD. (Starting NGINX and PHP) [duplicate]

I have a dockerfile that sets up NGINX, PHP, adds a Wordpress Repository. I want at boot time, to start PHP and NGINX. However, I am failing to do so. I tried adding the two commands in the CMD array, and I also tried to put them in a shell file and starting the shell file. Nothing worked. Below is my 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"]

I tried to put the commands in the CMD in a shell file, and run the shell file in the CMD command. It still didn't work. what am i missing?

like image 249
Nicolas El Khoury Avatar asked Apr 03 '18 13:04

Nicolas El Khoury


1 Answers

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"]

With this, you can put more complex logic in start.sh.

like image 99
atline Avatar answered Sep 21 '22 07:09

atline