简体   繁体   中英

Nginx in Docker container won't run PHP

I'm beginner with Docker, and I'm trying to build my own image: Ubuntu + Nginx + PHP.

So, I have a directory called test . Inside directory two other directories, app and sites-enabled . Also, there's a Dockerfile, with content:

FROM ubuntu:trusty

RUN apt-get update && \
    apt-get install -y nginx php5-fpm php5-mysql php-apc php5-imagick php5-imap php5-mcrypt php5-gd libssh2-php && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
ADD sites-enabled/ /etc/nginx/sites-enabled/
ADD app/ /app/

EXPOSE 80
CMD ["php5-fpm", "-c", "/etc/php5/fpm"]
CMD ["/usr/sbin/nginx"]

I build this image successfully. Then I create container with docker run -d image_name . I get the ID, and then I run docker inspect -f "{{.NetworkSettings.IPAddress}}" ID in order to get the IP address of the container.

I need this IP address, because I also run HAProxy in another container, so I can configure it to point to the right localtion.

So, both HAProxy and container with PHP app are running OK. HAProxy is pointing at the right application. PHP application files are uploaded at the right location inside the container.

But, Nginx doesn't execute PHP. Instead, when I try to access the application, I just get a downloaded file with my index.php PHP code.

What could be the problem? Please help.

My first guess was that I'm doing something wrong in Dockerfile when I run php5-fpm. I've tried few different ways, but non of them seem to work.

One CMD only.

If you need "services", look into supervisord or runit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM