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 ?