Docker Community Forums

Share and learn in the Docker community.

Docker with php built-in server


(Zimmicz) #1

Hi,
I’m trying to run php built-in server (`php -S localhost:8080) via docker, I cannot access site from the host though - I always end up with Connection reset.

Here’s a simple Dockerfile I build on:

FROM centos:centos6

RUN rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

RUN yum --enablerepo=remi,remi-php55 install -y php php-opcache php-cli php-pear php-common && yum clean all
RUN php -r "readfile('https://getcomposer.org/installer');" | php
RUN echo "date.timezone = Europe/Prague" >> /etc/php.ini
RUN mv composer.phar /usr/bin/composer
RUN php -r "eval('?>'.file_get_contents('http://backend.bolt80.com/piecrust/install'));"
RUN mv piecrust.phar /usr/bin/chef

CMD ["/bin/bash"]

Is it even possible to run this server with docker? While trying to make it work, I found out that when nginx was installed and set to listen on this very port, it is accessible from the host. PHP built-in server seems to be hidden from the host, thus not able to serve any requests though.

Anyone was successful making this work?


(Sven Dowideit) #2

I’m not sure how you’re starting your Docker container, but I’m guessing you may need to use the -p option to map the container’s port to your host - see http://docs.docker.com/examples/nodejs_web_app/ and http://docs.docker.com/reference/commandline/cli/#run


(Zimmicz) #3

I solved it with setting php server address to 0.0.0.0, which made it accessible from outside of the container.


(Sven Dowideit) #4

Ah yes, you’re right, services that default to listening to 127.0.0.1 only do cause problems.


(Zimmicz) #5

I solved it with setting php server address to 0.0.0.0, which made it
accessible from outside of the container.