Host specification when laravel php artisan serve in docker container

Must start with host = 0.0.0.0. By default, it listens at 127.0.0.1, but this is just listening inside the container. If you access it from the host pc with curl localhost, it will be converted to another internal ip when communicating inside the container. Therefore, if you listen on 127.0.0.1, you cannot respond. Therefore, listen with 0.0.0.0. This will listen on all interfaces in the container. Therefore, it becomes possible to respond.

↓ Code is supposed to be mounted on/app

FROM centos:centos8

RUN dnf module install -y php:7.4

WORKDIR /app
CMD [ "php", "artisan", "serve", "--port=80", "--host=0.0.0.0" ]

reference https://qiita.com/amuyikam/items/01a8c16e3ddbcc734a46

Recommended Posts

Host specification when laravel php artisan serve in docker container
Just install Laravel8 on docker in PHP8 environment
Check when the container cannot be accessed from Host in the Laravel on docker environment using VS Code's Remote container.
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
I got a Permission Denied error when I put Laravel in Docker
Install laravel/Dusk in docker environment (laravel6)
ubuntu: 20.04 Consideration memo to output GUI (output xeyes) to host side in docker container
I had to lower the PHP version in Docker + Composer + Laravel environment
Kind @ Mac in Docker and vctl container
[Docker] php artisan migrate error (SQLSTATE [HY000] [2002])
MySQL container does not start in Docker
Directly operate mariadb running in Docker container
[Docker] Copy files from docker container to host
[Docker] Start container, start bash in container, delete image
Japanese setting of mysql in Docker container
When composer install/require in the Docker container, it becomes `Could not find package`
Solved DB connection and CORS problem when developing Laravel × Nuxt.js in Docker environment