Add project files
This commit is contained in:
26
php-compose-project/docker-compose.override.yml
Normal file
26
php-compose-project/docker-compose.override.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html:delegated
|
||||||
|
environment:
|
||||||
|
- NGINX_HOST=localhost
|
||||||
|
- NGINX_PORT=80
|
||||||
|
|
||||||
|
php:
|
||||||
|
build:
|
||||||
|
context: ./docker/php
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html:delegated
|
||||||
|
environment:
|
||||||
|
- PHP_IDE_CONFIG=serverName=docker
|
||||||
|
extra_hosts:
|
||||||
|
- "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
db:
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
50
php-compose-project/docker-compose.yml
Normal file
50
php-compose-project/docker-compose.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- "8000:80"
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
depends_on:
|
||||||
|
- php
|
||||||
|
networks:
|
||||||
|
- frontend
|
||||||
|
- backend
|
||||||
|
|
||||||
|
php:
|
||||||
|
build:
|
||||||
|
context: ./docker/php
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
environment:
|
||||||
|
- DB_HOST=db
|
||||||
|
- DB_USER=root
|
||||||
|
- DB_PASS=secret
|
||||||
|
- DB_NAME=testdb
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: mysql:8.0
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=secret
|
||||||
|
- MYSQL_DATABASE=testdb
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
|
||||||
|
networks:
|
||||||
|
frontend:
|
||||||
|
backend:
|
||||||
|
internal: true
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
17
php-compose-project/docker/nginx/default.conf
Normal file
17
php-compose-project/docker/nginx/default.conf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /var/www/html;
|
||||||
|
index index.php index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_pass php:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
include fastcgi_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
php-compose-project/docker/php/Dockerfile
Normal file
27
php-compose-project/docker/php/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM php:8.1-fpm
|
||||||
|
|
||||||
|
# Abhängigkeiten installieren
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libzip-dev \
|
||||||
|
zip \
|
||||||
|
unzip
|
||||||
|
|
||||||
|
# PHP Extensions installieren
|
||||||
|
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||||
|
&& docker-php-ext-install -j$(nproc) \
|
||||||
|
gd \
|
||||||
|
pdo \
|
||||||
|
pdo_mysql \
|
||||||
|
zip
|
||||||
|
|
||||||
|
# OPCache für Produktion aktivieren
|
||||||
|
RUN docker-php-ext-install opcache \
|
||||||
|
&& docker-php-ext-enable opcache
|
||||||
|
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
# Produktionskonfiguration nutzen
|
||||||
|
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
|
||||||
30
php-compose-project/docker/php/Dockerfile.dev
Normal file
30
php-compose-project/docker/php/Dockerfile.dev
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
FROM php:8.1-fpm
|
||||||
|
|
||||||
|
# Abhängigkeiten installieren
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libzip-dev \
|
||||||
|
zip \
|
||||||
|
unzip
|
||||||
|
|
||||||
|
# PHP Extensions installieren
|
||||||
|
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||||
|
&& docker-php-ext-install -j$(nproc) \
|
||||||
|
gd \
|
||||||
|
pdo \
|
||||||
|
pdo_mysql \
|
||||||
|
zip
|
||||||
|
|
||||||
|
# Development-Konfiguration nutzen
|
||||||
|
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
|
||||||
|
|
||||||
|
# Xdebug installieren
|
||||||
|
RUN pecl install xdebug \
|
||||||
|
&& docker-php-ext-enable xdebug
|
||||||
|
|
||||||
|
# Xdebug-Konfiguration kopieren
|
||||||
|
COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
|
||||||
|
|
||||||
|
WORKDIR /var/www/html
|
||||||
7
php-compose-project/docker/php/xdebug.ini
Normal file
7
php-compose-project/docker/php/xdebug.ini
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
zend_extension=xdebug
|
||||||
|
|
||||||
|
xdebug.mode=develop,debug
|
||||||
|
xdebug.start_with_request=yes
|
||||||
|
xdebug.client_host=host.docker.internal
|
||||||
|
xdebug.client_port=9003
|
||||||
|
xdebug.log=/var/log/xdebug.log
|
||||||
59
php-compose-project/src/db-test.php
Normal file
59
php-compose-project/src/db-test.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
$host = getenv('DB_HOST') ?: 'db';
|
||||||
|
$user = getenv('DB_USER') ?: 'root';
|
||||||
|
$pass = getenv('DB_PASS') ?: 'secret';
|
||||||
|
$dbname = getenv('DB_NAME') ?: 'testdb';
|
||||||
|
|
||||||
|
echo "<h1>Datenbank-Verbindungstest</h1>";
|
||||||
|
echo "<p>Verbindungsversuch zu: $host</p>";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Verbindung erstellen
|
||||||
|
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||||
|
|
||||||
|
// PDO-Fehlerbehandlung aktivieren
|
||||||
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
echo "<div style='color:green;'>Verbindung erfolgreich!</div>";
|
||||||
|
|
||||||
|
// Prüfen, ob Testtabelle existiert, sonst erstellen
|
||||||
|
$stmt = $conn->query("SHOW TABLES LIKE 'test_table'");
|
||||||
|
if ($stmt->rowCount() == 0) {
|
||||||
|
$conn->exec("CREATE TABLE test_table (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
message VARCHAR(255),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 1')");
|
||||||
|
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 2')");
|
||||||
|
echo "<p>Testtabelle erstellt und mit Daten gefüllt.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Daten auslesen
|
||||||
|
$stmt = $conn->query("SELECT * FROM test_table");
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
echo "<h2>Daten aus der Datenbank:</h2>";
|
||||||
|
echo "<table border='1'>";
|
||||||
|
echo "<tr><th>ID</th><th>Nachricht</th><th>Erstellt am</th></tr>";
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td>" . $row['id'] . "</td>";
|
||||||
|
echo "<td>" . $row['message'] . "</td>";
|
||||||
|
echo "<td>" . $row['created_at'] . "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table>";
|
||||||
|
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
echo "<div style='color:red;'>Verbindungsfehler: " . $e->getMessage() . "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verbindung schließen
|
||||||
|
$conn = null;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<p>Seite geladen um: <?php echo date('H:i:s'); ?></p>
|
||||||
|
<p><a href="index.php">Zurück zur Startseite</a></p>
|
||||||
29
php-compose-project/src/image-test.php
Normal file
29
php-compose-project/src/image-test.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
// Test für GD Extension
|
||||||
|
header('Content-Type: image/png');
|
||||||
|
|
||||||
|
// Canvas erstellen (300x200px)
|
||||||
|
$image = imagecreatetruecolor(300, 200);
|
||||||
|
|
||||||
|
// Farben definieren
|
||||||
|
$background = imagecolorallocate($image, 0, 153, 204);
|
||||||
|
$text_color = imagecolorallocate($image, 255, 255, 255);
|
||||||
|
$border_color = imagecolorallocate($image, 0, 0, 0);
|
||||||
|
|
||||||
|
// Hintergrund füllen
|
||||||
|
imagefill($image, 0, 0, $background);
|
||||||
|
|
||||||
|
// Rahmen zeichnen
|
||||||
|
imagerectangle($image, 0, 0, 299, 199, $border_color);
|
||||||
|
|
||||||
|
// Text schreiben
|
||||||
|
$text = "GD funktioniert!";
|
||||||
|
imagestring($image, 5, 60, 80, $text, $text_color);
|
||||||
|
|
||||||
|
// Zeit anzeigen
|
||||||
|
$time = date('H:i:s');
|
||||||
|
imagestring($image, 3, 100, 120, "Zeit: $time", $text_color);
|
||||||
|
|
||||||
|
// Bild ausgeben
|
||||||
|
imagepng($image);
|
||||||
|
imagedestroy($image);
|
||||||
36
php-compose-project/src/index.php
Normal file
36
php-compose-project/src/index.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>PHP Docker Demo</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
||||||
|
h1 { color: #0066cc; }
|
||||||
|
.info { background-color: #f0f0f0; padding: 15px; border-radius: 5px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>PHP-FPM mit Nginx Docker Demo</h1>
|
||||||
|
|
||||||
|
<div class="info">
|
||||||
|
<p>PHP Version: <?php echo phpversion(); ?></p>
|
||||||
|
<p>Server Software: <?php echo $_SERVER['SERVER_SOFTWARE']; ?></p>
|
||||||
|
<p>Ausgeführt von: <?php echo exec('whoami'); ?></p>
|
||||||
|
<p>Zeitstempel: <?php echo date('Y-m-d H:i:s'); ?></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Extension Tests</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="image-test.php">GD Image Test</a> (benötigt GD Extension)</li>
|
||||||
|
<li><a href="db-test.php">Datenbank-Test</a> (benötigt MySQL/MariaDB Verbindung)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Installierte PHP Extensions:</h3>
|
||||||
|
<ul>
|
||||||
|
<?php foreach(get_loaded_extensions() as $ext): ?>
|
||||||
|
<li><?php echo $ext; ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
18
php-project/Dockerfile
Normal file
18
php-project/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
FROM php:8.1-cli
|
||||||
|
|
||||||
|
# GD Extension installieren
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libpng-dev \
|
||||||
|
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||||
|
&& docker-php-ext-install -j$(nproc) gd
|
||||||
|
|
||||||
|
# PDO MySQL Extension installieren
|
||||||
|
RUN docker-php-ext-install pdo pdo_mysql
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ./src .
|
||||||
|
|
||||||
|
# Entwicklungsserver starten
|
||||||
|
CMD ["php", "-S", "0.0.0.0:8000"]
|
||||||
34
php-project/docker-compose.yml
Normal file
34
php-project/docker-compose.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
php-app:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
volumes:
|
||||||
|
- ./src:/app
|
||||||
|
environment:
|
||||||
|
DB_HOST: mysql-db
|
||||||
|
DB_USER: root
|
||||||
|
DB_PASSWORD: secret
|
||||||
|
DB_NAME: testdb
|
||||||
|
depends_on:
|
||||||
|
- mysql-db
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
|
||||||
|
mysql-db:
|
||||||
|
image: mysql:8.0
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: secret
|
||||||
|
MYSQL_DATABASE: testdb
|
||||||
|
volumes:
|
||||||
|
- db-data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
app-network:
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db-data:
|
||||||
59
php-project/src/db-test.php
Normal file
59
php-project/src/db-test.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
$host = getenv('DB_HOST') ?: 'mysql-db';
|
||||||
|
$user = getenv('DB_USER') ?: 'root';
|
||||||
|
$pass = getenv('DB_PASSWORD') ?: 'secret';
|
||||||
|
$dbname = getenv('DB_NAME') ?: 'testdb';
|
||||||
|
|
||||||
|
echo "<h1>Datenbank-Verbindungstest</h1>";
|
||||||
|
echo "<p>Verbindungsversuch zu: $host</p>";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Verbindung erstellen
|
||||||
|
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||||
|
|
||||||
|
// PDO-Fehlerbehandlung aktivieren
|
||||||
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
echo "<div style='color:green;'>Verbindung erfolgreich!</div>";
|
||||||
|
|
||||||
|
// Prüfen, ob Testtabelle existiert, sonst erstellen
|
||||||
|
$stmt = $conn->query("SHOW TABLES LIKE 'test_table'");
|
||||||
|
if ($stmt->rowCount() == 0) {
|
||||||
|
$conn->exec("CREATE TABLE test_table (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
message VARCHAR(255),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
|
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 1')");
|
||||||
|
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 2')");
|
||||||
|
echo "<p>Testtabelle erstellt und mit Daten gefüllt.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Daten auslesen
|
||||||
|
$stmt = $conn->query("SELECT * FROM test_table");
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
echo "<h2>Daten aus der Datenbank:</h2>";
|
||||||
|
echo "<table border='1'>";
|
||||||
|
echo "<tr><th>ID</th><th>Nachricht</th><th>Erstellt am</th></tr>";
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
echo "<tr>";
|
||||||
|
echo "<td>" . $row['id'] . "</td>";
|
||||||
|
echo "<td>" . $row['message'] . "</td>";
|
||||||
|
echo "<td>" . $row['created_at'] . "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table>";
|
||||||
|
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
echo "<div style='color:red;'>Verbindungsfehler: " . $e->getMessage() . "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verbindung schließen
|
||||||
|
$conn = null;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<p>Seite geladen um: <?php echo date('H:i:s'); ?></p>
|
||||||
|
<p><a href="index.php">Zurück zur Startseite</a></p>
|
||||||
29
php-project/src/image-test.php
Normal file
29
php-project/src/image-test.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
// Test für GD Extension
|
||||||
|
header('Content-Type: image/png');
|
||||||
|
|
||||||
|
// Canvas erstellen (300x200px)
|
||||||
|
$image = imagecreatetruecolor(300, 200);
|
||||||
|
|
||||||
|
// Farben definieren
|
||||||
|
$background = imagecolorallocate($image, 0, 153, 204);
|
||||||
|
$text_color = imagecolorallocate($image, 255, 255, 255);
|
||||||
|
$border_color = imagecolorallocate($image, 0, 0, 0);
|
||||||
|
|
||||||
|
// Hintergrund füllen
|
||||||
|
imagefill($image, 0, 0, $background);
|
||||||
|
|
||||||
|
// Rahmen zeichnen
|
||||||
|
imagerectangle($image, 0, 0, 299, 199, $border_color);
|
||||||
|
|
||||||
|
// Text schreiben
|
||||||
|
$text = "GD funktioniert!";
|
||||||
|
imagestring($image, 5, 60, 80, $text, $text_color);
|
||||||
|
|
||||||
|
// Zeit anzeigen
|
||||||
|
$time = date('H:i:s');
|
||||||
|
imagestring($image, 3, 100, 120, "Zeit: $time", $text_color);
|
||||||
|
|
||||||
|
// Bild ausgeben
|
||||||
|
imagepng($image);
|
||||||
|
imagedestroy($image);
|
||||||
22
php-project/src/index.php
Normal file
22
php-project/src/index.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>PHP Docker Demo</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>PHP Docker Demo</h1>
|
||||||
|
|
||||||
|
<h2>PHP Info</h2>
|
||||||
|
<p>PHP Version: <?php echo phpversion(); ?></p>
|
||||||
|
|
||||||
|
<h2>Tests</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="image-test.php">GD Image Test</a> (benötigt GD Extension)</li>
|
||||||
|
<li><a href="db-test.php">Datenbank-Test</a> (benötigt MySQL/MariaDB Verbindung)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Diese Datei wurde geladen um: <?php echo date('H:i:s'); ?></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
react-project/.dockerignore
Normal file
7
react-project/.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
build
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
30
react-project/Dockerfile
Normal file
30
react-project/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Build-Stage
|
||||||
|
FROM node:16 AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Abhängigkeiten zuerst kopieren und installieren (für besseres Caching)
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Den Rest der Anwendung kopieren
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build-Zeit-Variable setzen
|
||||||
|
ENV REACT_APP_BUILD_TIME="$(date)"
|
||||||
|
|
||||||
|
# Anwendung bauen
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production-Stage
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# Build-Output vom build-Stage kopieren
|
||||||
|
COPY --from=build /app/build /usr/share/nginx/html
|
||||||
|
|
||||||
|
# Nginx-Konfiguration (optional)
|
||||||
|
# COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
30
react-project/package.json
Normal file
30
react-project/package.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "react-docker-demo",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"react-scripts": "5.0.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
15
react-project/public/index.html
Normal file
15
react-project/public/index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta name="description" content="React Docker Demo App" />
|
||||||
|
<title>React Docker Demo</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
42
react-project/src/App.css
Normal file
42
react-project/src/App.css
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
.App {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-header {
|
||||||
|
background-color: #282c34;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: calc(10px + 2vmin);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.counter {
|
||||||
|
margin: 2rem 0;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: #61dafb;
|
||||||
|
border: none;
|
||||||
|
color: #282c34;
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: #4fa8c3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
margin-top: 2rem;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
28
react-project/src/App.js
vendored
Normal file
28
react-project/src/App.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="App">
|
||||||
|
<header className="App-header">
|
||||||
|
<h1>React Docker Demo</h1>
|
||||||
|
<p>Diese App läuft in einem Docker-Container</p>
|
||||||
|
|
||||||
|
<div className="counter">
|
||||||
|
<p>Du hast den Button {count} mal geklickt</p>
|
||||||
|
<button onClick={() => setCount(count + 1)}>
|
||||||
|
Klick mich!
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="info">
|
||||||
|
Build-Zeit: {process.env.REACT_APP_BUILD_TIME || 'Unbekannt'}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
13
react-project/src/index.css
Normal file
13
react-project/src/index.css
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||||
|
sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||||
|
monospace;
|
||||||
|
}
|
||||||
11
react-project/src/index.js
vendored
Normal file
11
react-project/src/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom/client';
|
||||||
|
import './index.css';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
|
root.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user