'After docker compose localhost:8000 not open page in browser

Hello i'm newbie in docker. I have project on laravel 9 with node version 12.14.0,PostgreSql 10,PHP 8.1.2 This my git repository:https://github.com/Daniil1996-vrn/DEVJuniorPHP/tree/main/DEVJuniorPHP I create docker file, webserver ngnix conf file (but when i'm creating project i usr artisan server) on this repository:https://github.com/othyn/docker-compose-laravel#running-attached This is my docker-compose.yml:

version: "3.7"

networks:
  laravel:

volumes:
  database:

services:
  database:
    image: postgres:10
    container_name: postgres
    restart: "no"
    volumes:
      - .:/var/lib/postgresql/data
    networks:
      - laravel
    ports:
      - 5432:5432
    environment:
      
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "admin1234"
      POSTGRES_DB: "DEVJuniorPHP"
      
      
    

  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ./:/app
    working_dir: /app
    command: composer install

  node:
    image: node:12
    container_name: node
    volumes:
      - ./:/app
    working_dir: /app
    command: npm install

  app:
    container_name: app
    restart: "no"
    volumes:
      - ./:/var/www
      
    networks:
      - laravel
    depends_on:
      - composer
      - node
    build:
      context: .
      dockerfile: ./docker/app/dockerfile
    
    command: php-fpm

  webserver:
    image: nginx:stable
    container_name: webserver
    restart: "no"
    volumes:
      - ./:/var/www
      - ./docker/webserver/nginx.conf/
    networks:
      - laravel
    ports:
      - 8000:8000
    depends_on:
      - database
      - app

Docker File:

FROM php:8.1.4-fpm-alpine3.14

# Update package manager ready for deps to be installed
RUN apk update



# Set the working directory of the container to the hosted directory
WORKDIR /var/www

nginx.conf:

server {
    listen 8000;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;

        # Uncomment to extend nginx's max timeout to 1 hour
        # fastcgi_read_timeout 3600;
    }
}

When i run command in terminal Visual Studio code docker-compose up -d i next have messagess in terminal: Starting node ... done Starting composer ... done Starting postgres ... Starting postgres ... done Recreating webserver ... done PS D:\DEVJuniorPHP\DEVJuniorPHP> docker-compose up -d Starting node ... done Starting postgres ... Starting postgres ... done app is up-to-date webserver is up-to-date

But whene i go to page localhost:8000 in browser i see the message:Can't access site Please help me resolve this problem



Solution 1:[1]

Error is that the nginx vhost is pointing to the wrong folder.

You didn't map the nginx.conf volume into the container volume so it doesn't really find the path to the application. In the volume part of the webserver service, you must put the path of the vhost container:

- ./docker/webserver/nginx.conf:/etc/nginx/nginx.conf

Get back to me if it's good !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cheick