Laravel running inside docker successfully but unable to see anything in the browser?

  docker, docker-compose, laravel, laravel-8

Have been following this tutorial making a few changes when needed: https://medium.com/@pierangelo1982/dockerize-an-existing-laravel-application-with-docker-compose-a45eb7956cbd

After running docker-composer build and docker-composer up all the migrations run successfully and I get a message saying the app is running on http://0.0.0.0:8000 Hover that url or the one specified in the tutorial show nothing.

Here is my docker file

FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181

my docker-compose.yaml file

version: '2'
services:
  app:
    build: .
    ports:
      - '8009:8000'
    volumes:
      - .:/app
    env_file: .env
    working_dir: /app
    command: bash -c 'composer install && php artisan migrate && php artisan serve --host 0.0.0.0'
    depends_on:
      - db
    links:
      - db
  db:
    image: 'mysql:5.7'
    environment:
      - MYSQL_ROOT_PASSWORD=1
      - MYSQL_DATABASE=posts
      - MYSQL_PASSWORD=1
    volumes:
      - ./data/:/var/lib/mysql
    ports:
      - '3306:3306'
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8090:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: 1

and my .env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:oD3DGqKdE7ne91FGu7YJzAJo721v56uVjAZGRGT6VNk=
APP_DEBUG=true
APP_URL=http://posts.test

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=posts
DB_USERNAME=root
DB_PASSWORD=1

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Not really sure what is happening at this point since it seems everything is running fine but then I see nothing on the specified port.

Source: Laravel

Leave a Reply