Search code examples
laraveldockerdocker-run

Run Laravel docker image with exposing ports -p


I have a laravel app but I can't make it run with docker run command. The last two instructions are

EXPOSE 9000
CMD ["php", "artisan", "serve","--port=9000"]

I am trying to make it run trying with:

docker run -p 9000:9000 my_image:latest
docker run --net="host" -p 9000:9000 my_image:latest
docker run --net="bridge" -p 9000:9000 my_image:latest

The only thing I see is the classic laravel output

Laravel development server started: <http://127.0.0.1:9000>

What am I missing?


Solution

  • The problem is 127.0.0.1:9000, i.e., the server is bound to localhost within the container, instead of listening on an external interface. The solution is to use the --host 0.0.0.0 argument, which will bind the server to all available interfaces.

    CMD ["php", "artisan", "serve", "--host", "0.0.0.0", "--port=9000"]