Docker-Compose & Laravel connect front and back

How can I set up my docker-compose and docker file to run my app?


When I try to get the web page http://localhost:8000/

I get a black page and those errors in the console:

GET http://localhost:5173/@vite/client net::ERR_EMPTY_RESPONSE

GET http://localhost:5173/resources/js/app.js net::ERR_EMPTY_RESPONSE


If I try to get the http://ibi-system-test/ I can not and see

This site can’t be reached

ibi-system-test refused to connect.


My code

my Dockerfile

FROM php:8.3.4-apache as web

RUN apt-get update -y 
RUN apt-get install -y unzip zip libpq-dev libcurl4-gnutls-dev libicu-dev nano libzip-dev
RUN docker-php-ext-configure intl 

# PHP extensions
RUN docker-php-ext-install pdo pdo_mysql bcmath intl zip

# Mod Rewrite
RUN a2enmod rewrite

# Composer
COPY --from=composer:2.7.2 /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

# apache config
COPY ./Docker/apache.conf /usr/local/apache2/conf/httpd.conf

COPY . .

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

RUN chown -R www-data:www-data /var/www/html/storage
RUN chmod -R 777 /var/www/html/storage

ENTRYPOINT [ "entrypoint.sh" ]

# ===== NODE ===== NODE ===== NODE ===== NODE ===== NODE ===== 
FROM node:20.12.0 as node

WORKDIR /var/www/html/
COPY . .

RUN npm install --global cross-env

VOLUME /var/www/html/node_modules

CMD ["npm", "run", "dev"]

my docker-compose file

version: "3.8"
services:
    # Web Service
    web:
        container_name: ibi_system_app_test
        depends_on:
            - database
            - node
        build:
            context: .
            target: web
            args:
                - APP_ENV=${APP_ENV}
        environment:
            - APP_ENV=${APP_ENV}
            - CONTAINER_ROLE=app
        volumes:
            - ./:/var/www/html
        ports:
            - 8000:80
        hostname: ${HOST_NAME}
        domainname: ${APP_URL}

    # Database Server
    database:
        container_name: database_test
        image: mysql:8.0
        ports:
            - 3306:3306
        environment:
            - MYSQL_DATABASE=${DB_DATABASE}
            - MYSQL_USER=${DB_USERNAME}
            - MYSQL_PASSWORD=${DB_PASSWORD}
            - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
        volumes:
            - db-data:/var/lib/mysql

    # Node Server
    node:
        container_name: node_test
        build:
            context: .
            target: node
        volumes:
            - ./node_modules:/usr/src/node_modules
        tty: true
        ports:
            - 5173:5173 # Expose Vite port

    # PHP myadmin
    phpmyadmin:
        container_name: phpmyadmin_test
        depends_on:
            - database
        image: phpmyadmin/phpmyadmin
        environment:
            - PMA_HOST=database
            - PMA_PORT=3306
        ports:
            - 8001:80

volumes:
    db-data: ~

my entrypoint.sh file that I run in the Dockerfile

#!/bin/bash
echo "test."

if [ ! -f "vendor/autoload.php" ]; then
    echo "Installing composer dependencies."
    composer install --no-progress --no-interaction
fi

if [ ! -f ".env" ]; then
    echo "Creating env file for env $APP_ENV"
    cp .env.example .env
else
    echo "env file exists."
fi

role=${CONTAINER_ROLE:-app}
echo "role - $role"

if [ "$role" = "app" ]; then
    php artisan migrate
    php artisan key:generate
    php artisan view:clear 
    php artisan cache:clear
    php artisan config:clear
    php artisan route:clear
    
    apache2-foreground
fi

the apache.conf file

<VirtualHost *:80>
    ServerAdmin webmaster@ibi-system-test
    DocumentRoot "/var/www/html/public"
    ServerName ibi-system-test
    ServerAlias www.ibi-system-test

    <Directory "/var/www/html/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The vite config

/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue2";
import postcss from "./postcss.config";

export default defineConfig({
    plugins: [
        laravel({
            input: ["resources/js/app.js"],
            postcss,
            refresh: true,
        }),
        vue(),
    ],
    define: {
        "process.env": process.env,
    },
    resolve: {
        alias: {
            vue: "vue/dist/vue.esm.js",
            "~": "/resources/js",
        },
    },
    server: {
        hmr: {
            port: 8000,
            host: "ibi-system-test",
        },
    },
});

my .env file is

APP_NAME=ibi_system_app_test
APP_ENV=development
APP_KEY=....
APP_DEBUG=true
APP_URL=http://ibi-system-test

VITE_APP_URL=http://ibi-system-test
VITE_API_URL=http://ibi-system-test/api

HOST_NAME=ibi-system-test

How I can solve this problem?

Another question

Is ok that I spread the node to another container/service ? or I can install node and npm in the web service ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật