I was creating docker container for laravel with postgres. containers running but cant find laravel in web.
Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install
WORKDIR /var/www/html
COPY . .
CMD php artisan serve --host=0.0.0.0
EXPOSE 8000
My docker-compose.yml file
version: '3'
services:
php_3:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/var/www/html
ports:
- "8000:8000"
postgres_3:
image: postgres:12.3-alpine
restart: unless-stopped
ports:
- "5431:5432"
volumes:
- ./docker/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: lara_3
Without error both services are running but cant find laravel runnning in browser. what i want to change.please help me to fix this.
2
Answers
In Dockerfile instead of
php artisan serve --host=0.0.0.0
write:
php artisan serve --host=0.0.0.0 --port=80
and EXPOSE 80
When you install php-fpm what you get is a server process, and then you need to config nginx to forward all requests to php files to be parsed by this php-fpm process.
Alternatively you can install php-apache docker image that include the apache server.
docker-compose.yml
Dockerfile
conf/nginx.conf