I am new to Docker, I am trying to set up a Docker configuration for adding Php, Nginx, Mysql, Bootstrap and Sb Admin 2 Theme. But the css is not loaded properly. Below the configuration:
docker-compose.yml
version: '3.3'
services:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
– ./www:/var/www/html
depends_on:
– mysql
nginx:
image: nginx:latest
ports:
– “8080:80”
volumes:
– ./nginx.conf:/etc/nginx/nginx.conf
– ./www:/var/www/html
depends_on:
– php
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: my_database
volumes:
– mysql_data:/var/lib/mysql
volumes:
mysql_data:
Dockerfile
# Use the official PHP image with Apache
FROM php:7.4-fpm
ENV NODE_VERSION=18.17.0
# Set working directory
WORKDIR /var/www/html
# Install system dependencies
RUN apt-get update && apt-get install -y
build-essential
libpng-dev
libjpeg62-turbo-dev
libfreetype6-dev
locales
zip
jpegoptim optipng pngquant gifsicle
vim
unzip
git
curl
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql exif pcntl bcmath gd
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Node.js and npm
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - &&
apt-get install -y nodejs
# Copy the application files
COPY ./www /var/www/html
# Install npm dependencies
RUN cd /var/www/html && npm install && npm run build
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/'
}
}
]
}
]
}
};
index.js
import 'bootstrap/dist/css/bootstrap.min.css';
import 'startbootstrap-sb-admin-2/css/sb-admin-2.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import 'jquery';
import 'startbootstrap-sb-admin-2/js/sb-admin-2.min';
// You can add custom JavaScript code here
console.log("Hello from Webpack!");
This is the page where I like to use the SB Admin template
login.html
Below the structure of the project:
enter image description here
This is the result while loading login.html:
enter image description here
I am using:
Node v22.4.0
Npm 10.8.1
Docker version 19.03.8
Does anybody have an idea?
Thanks in advance
Matteo Simone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.