Skip to content
Advertisement

A little problem with starting Laravel server in docker container

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS          PORTS                               NAMES
369caac73fe5   php:7.4.6-apache   "docker-php-entrypoi…"   48 minutes ago   Up 23 minutes   80/tcp, 0.0.0.0:8000->8000/tcp      web_laravel

I have deployed the Laravel 8.x source code in web_laravel docker. I did not get any error while running composer update and php artisan serve.

# php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Mon Jan  20:01:04 2021] PHP 7.4.6 Development Server (http://127.0.0.1:8000) started

But, when I access 192.168.1.xx:8000 in browser, I get the following error.

192.168.1.xx refuses to connect

I tried to ping 192.168.1.xx, it works fine. But, I got the following error when using telnet.

$ telnet 192.168.1.xx 8000
Trying 192.168.1.xx...
telnet: Unable to connect to remote host: Connection refused

It seems that I am having a little problem with starting Laravel server in docker. Could anybody help me?

Advertisement

Answer

Solved:


As far as I know, each docker has an IP address. So, I have to start the server with the IP address of docker container. However, to avoid errors from docker’s dynamic IP address, I use 0.0.0.0 instead of the IP address of web_laravel docker because 0.0.0.0 means all IPv4 addresses on the local machine. I use the following command.

php artisan serve --host 0.0.0.0
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement