Add project files
This commit is contained in:
18
00_uebungs-files/01_docker-basics-php/Dockerfile
Normal file
18
00_uebungs-files/01_docker-basics-php/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
00_uebungs-files/01_docker-basics-php/docker-compose.yml
Normal file
34
00_uebungs-files/01_docker-basics-php/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
00_uebungs-files/01_docker-basics-php/src/db-test.php
Normal file
59
00_uebungs-files/01_docker-basics-php/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
00_uebungs-files/01_docker-basics-php/src/image-test.php
Normal file
29
00_uebungs-files/01_docker-basics-php/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
00_uebungs-files/01_docker-basics-php/src/index.php
Normal file
22
00_uebungs-files/01_docker-basics-php/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
00_uebungs-files/02_docker-basics-react/.dockerignore
Normal file
7
00_uebungs-files/02_docker-basics-react/.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
build
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
30
00_uebungs-files/02_docker-basics-react/Dockerfile
Normal file
30
00_uebungs-files/02_docker-basics-react/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
|
||||||
|
RUN echo "REACT_APP_BUILD_TIME=$(date)" > .env
|
||||||
|
|
||||||
|
# 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
00_uebungs-files/02_docker-basics-react/package.json
Normal file
30
00_uebungs-files/02_docker-basics-react/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
00_uebungs-files/02_docker-basics-react/public/index.html
Normal file
15
00_uebungs-files/02_docker-basics-react/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
00_uebungs-files/02_docker-basics-react/src/App.css
Normal file
42
00_uebungs-files/02_docker-basics-react/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
00_uebungs-files/02_docker-basics-react/src/App.js
Normal file
28
00_uebungs-files/02_docker-basics-react/src/App.js
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
00_uebungs-files/02_docker-basics-react/src/index.css
Normal file
13
00_uebungs-files/02_docker-basics-react/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
00_uebungs-files/02_docker-basics-react/src/index.js
Normal file
11
00_uebungs-files/02_docker-basics-react/src/index.js
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>
|
||||||
|
);
|
||||||
@@ -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
00_uebungs-files/03_docker-compose/docker-compose.yml
Normal file
50
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/docker/nginx/default.conf
Normal file
17
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/docker/php/Dockerfile
Normal file
27
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/docker/php/Dockerfile.dev
Normal file
30
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/docker/php/xdebug.ini
Normal file
7
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/src/db-test.php
Normal file
59
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/src/image-test.php
Normal file
29
00_uebungs-files/03_docker-compose/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
00_uebungs-files/03_docker-compose/src/index.php
Normal file
36
00_uebungs-files/03_docker-compose/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>
|
||||||
20
00_vortrags-files/Dockerfile
Normal file
20
00_vortrags-files/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM php:8.1-fpm
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
COPY composer.json ./
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
zip \
|
||||||
|
unzip \
|
||||||
|
&& docker-php-ext-install pdo pdo_mysql
|
||||||
|
|
||||||
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
|
||||||
|
RUN composer install --no-scripts --no-autoloader
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN composer dump-autoload --optimize
|
||||||
|
|
||||||
|
EXPOSE 9000
|
||||||
|
CMD ["php-fpm"]
|
||||||
14
00_vortrags-files/composer.json
Normal file
14
00_vortrags-files/composer.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "example/php-docker-demo",
|
||||||
|
"description": "Eine einfache PHP-Anwendung für Docker",
|
||||||
|
"type": "project",
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.1",
|
||||||
|
"monolog/monolog": "^2.8"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
00_vortrags-files/nginx.conf
Normal file
29
00_vortrags-files/nginx.conf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 9090;
|
||||||
|
server_name localhost;
|
||||||
|
root /var/www/html/public;
|
||||||
|
index index.php;
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
include fastcgi_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include servers/*;
|
||||||
|
}
|
||||||
69
00_vortrags-files/public/index.php
Normal file
69
00_vortrags-files/public/index.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use App\HelloWorld;
|
||||||
|
use App\Database;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\Handler\StreamHandler;
|
||||||
|
|
||||||
|
// Logger initialisieren
|
||||||
|
$log = new Logger('app');
|
||||||
|
$log->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
|
||||||
|
|
||||||
|
$log->info('Anwendung gestartet');
|
||||||
|
|
||||||
|
// HelloWorld-Klasse verwenden
|
||||||
|
$hello = new HelloWorld();
|
||||||
|
$message = $hello->getMessage();
|
||||||
|
|
||||||
|
// Datenbankverbindung testen
|
||||||
|
$dbConfig = [
|
||||||
|
'host' => getenv('DB_HOST') ?: 'localhost',
|
||||||
|
'user' => getenv('DB_USER') ?: 'root',
|
||||||
|
'pass' => getenv('DB_PASS') ?: 'secret',
|
||||||
|
'name' => getenv('DB_NAME') ?: 'test'
|
||||||
|
];
|
||||||
|
|
||||||
|
$db = new Database($dbConfig);
|
||||||
|
$dbStatus = $db->testConnection() ? 'erfolgreich' : 'fehlgeschlagen';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Docker PHP Demo</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; }
|
||||||
|
.container { max-width: 800px; margin: 0 auto; }
|
||||||
|
.status { padding: 10px; margin: 10px 0; border-radius: 4px; }
|
||||||
|
.success { background-color: #d4edda; color: #155724; }
|
||||||
|
.error { background-color: #f8d7da; color: #721c24; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>PHP Docker Demo</h1>
|
||||||
|
<p>Dies ist eine einfache PHP-Anwendung für Docker-Demo.</p>
|
||||||
|
|
||||||
|
<h2>Status</h2>
|
||||||
|
<div class="status success">
|
||||||
|
<p><?php echo $message; ?></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Datenbankverbindung</h2>
|
||||||
|
<div class="status <?php echo $dbStatus === 'erfolgreich' ? 'success' : 'error'; ?>">
|
||||||
|
<p>Verbindung: <?php echo $dbStatus; ?></p>
|
||||||
|
<p>Host: <?php echo $dbConfig['host']; ?></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>PHP Info</h2>
|
||||||
|
<p>PHP Version: <?php echo phpversion(); ?></p>
|
||||||
|
<p>Loaded Extensions:</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach(get_loaded_extensions() as $ext): ?>
|
||||||
|
<li><?php echo $ext; ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
41
00_vortrags-files/src/Database.php
Normal file
41
00_vortrags-files/src/Database.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
class Database
|
||||||
|
{
|
||||||
|
private array $config;
|
||||||
|
|
||||||
|
public function __construct(array $config)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnection(): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$dsn = sprintf(
|
||||||
|
'mysql:host=%s;dbname=%s',
|
||||||
|
$this->config['host'],
|
||||||
|
$this->config['name']
|
||||||
|
);
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||||
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||||
|
\PDO::ATTR_TIMEOUT => 5,
|
||||||
|
];
|
||||||
|
|
||||||
|
$pdo = new \PDO(
|
||||||
|
$dsn,
|
||||||
|
$this->config['user'],
|
||||||
|
$this->config['pass'],
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
// In einer realen Anwendung würde hier geloggt werden
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
00_vortrags-files/src/HelloWorld.php
Normal file
10
00_vortrags-files/src/HelloWorld.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
class HelloWorld
|
||||||
|
{
|
||||||
|
public function getMessage(): string
|
||||||
|
{
|
||||||
|
return 'Hallo Welt! Die PHP-Anwendung läuft in Docker.';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,12 @@
|
|||||||
docker search nginx
|
docker search nginx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Offizielle Images mit Doku
|
||||||
|
- [https://hub.docker.com/_/mysql](https://hub.docker.com/_/mysql)
|
||||||
|
- [https://hub.docker.com/_/nginx](https://hub.docker.com/_/nginx)
|
||||||
|
- [https://hub.docker.com/_/node](https://hub.docker.com/_/node)
|
||||||
|
- [https://hub.docker.com/_/php](https://hub.docker.com/_/php)
|
||||||
|
|
||||||
### Images und Container
|
### Images und Container
|
||||||
- **Image**: Unveränderbare Vorlage
|
- **Image**: Unveränderbare Vorlage
|
||||||
```bash
|
```bash
|
||||||
@@ -49,15 +55,22 @@
|
|||||||
```dockerfile
|
```dockerfile
|
||||||
FROM php:8.1-fpm
|
FROM php:8.1-fpm
|
||||||
WORKDIR /var/www/html
|
WORKDIR /var/www/html
|
||||||
COPY composer.json composer.lock ./
|
|
||||||
|
COPY composer.json ./
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
zip \
|
zip \
|
||||||
unzip \
|
unzip \
|
||||||
&& docker-php-ext-install pdo pdo_mysql
|
&& docker-php-ext-install pdo pdo_mysql
|
||||||
|
|
||||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
|
||||||
RUN composer install --no-scripts --no-autoloader
|
RUN composer install --no-scripts --no-autoloader
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN composer dump-autoload --optimize
|
RUN composer dump-autoload --optimize
|
||||||
|
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
CMD ["php-fpm"]
|
CMD ["php-fpm"]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user