I am trying to run symfony using docker. This is my dockerfile
# Dockerfile
FROM php:7.2-cli
RUN apt-get update -y && apt-get install -y libmcrypt-dev
ENV COMPOSER_ALLOW_SUPERUSER=1
# install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer --ansi --version --no-interaction
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer --ansi --version --no-interaction
RUN docker-php-ext-install pdo mbstring
WORKDIR /app
COPY . /app
# RUN composer install --no-scripts --no-autoloader --ansi --no-interaction
EXPOSE 8000
CMD php -S localhost:8000 -t public 0.0.0.0:8000
After I build and run $ docker run -it -p 8000:8000 symfony-tutorial
I get following response
D:\docker_test\symfony-4-tutorial>docker run -it -p 8000:8000 symfony-tutorial
PHP 7.2.34 Development Server started at Wed Jan 11 16:40:32 2023
Listening on http://localhost:8000
Document root is /app/public
Press Ctrl-C to quit.
But on browser, its empty. This page isn’t workinglocalhost didn’t send any data. ERR_EMPTY_RESPONSE. There is nothing in source and network tab
CodePudding user response:
Your web server binds to localhost, which means that it'll only accept connections from inside the container.
You need to change
CMD php -S localhost:8000 -t public 0.0.0.0:8000
to
CMD php -S 0.0.0.0:8000 -t public 0.0.0.0:8000