diff --git a/php-compose-project/docker-compose.override.yml b/php-compose-project/docker-compose.override.yml new file mode 100644 index 0000000..ebd735c --- /dev/null +++ b/php-compose-project/docker-compose.override.yml @@ -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" diff --git a/php-compose-project/docker-compose.yml b/php-compose-project/docker-compose.yml new file mode 100644 index 0000000..15e3246 --- /dev/null +++ b/php-compose-project/docker-compose.yml @@ -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: diff --git a/php-compose-project/docker/nginx/default.conf b/php-compose-project/docker/nginx/default.conf new file mode 100644 index 0000000..7955530 --- /dev/null +++ b/php-compose-project/docker/nginx/default.conf @@ -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; + } +} diff --git a/php-compose-project/docker/php/Dockerfile b/php-compose-project/docker/php/Dockerfile new file mode 100644 index 0000000..82e17fb --- /dev/null +++ b/php-compose-project/docker/php/Dockerfile @@ -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 diff --git a/php-compose-project/docker/php/Dockerfile.dev b/php-compose-project/docker/php/Dockerfile.dev new file mode 100644 index 0000000..a283021 --- /dev/null +++ b/php-compose-project/docker/php/Dockerfile.dev @@ -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 diff --git a/php-compose-project/docker/php/xdebug.ini b/php-compose-project/docker/php/xdebug.ini new file mode 100644 index 0000000..9dd712f --- /dev/null +++ b/php-compose-project/docker/php/xdebug.ini @@ -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 diff --git a/php-compose-project/src/db-test.php b/php-compose-project/src/db-test.php new file mode 100644 index 0000000..e9e7ed3 --- /dev/null +++ b/php-compose-project/src/db-test.php @@ -0,0 +1,59 @@ +Datenbank-Verbindungstest"; +echo "
Verbindungsversuch zu: $host
"; + +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 "Testtabelle erstellt und mit Daten gefüllt.
"; + } + + // Daten auslesen + $stmt = $conn->query("SELECT * FROM test_table"); + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo "| ID | Nachricht | Erstellt am |
|---|---|---|
| " . $row['id'] . " | "; + echo "" . $row['message'] . " | "; + echo "" . $row['created_at'] . " | "; + echo "
Seite geladen um:
+ diff --git a/php-compose-project/src/image-test.php b/php-compose-project/src/image-test.php new file mode 100644 index 0000000..b0a42ee --- /dev/null +++ b/php-compose-project/src/image-test.php @@ -0,0 +1,29 @@ + + + + + +PHP Version:
+Server Software:
+Ausgeführt von:
+Zeitstempel:
+Verbindungsversuch zu: $host
"; + +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 "Testtabelle erstellt und mit Daten gefüllt.
"; + } + + // Daten auslesen + $stmt = $conn->query("SELECT * FROM test_table"); + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo "| ID | Nachricht | Erstellt am |
|---|---|---|
| " . $row['id'] . " | "; + echo "" . $row['message'] . " | "; + echo "" . $row['created_at'] . " | "; + echo "
Seite geladen um:
+ diff --git a/php-project/src/image-test.php b/php-project/src/image-test.php new file mode 100644 index 0000000..b0a42ee --- /dev/null +++ b/php-project/src/image-test.php @@ -0,0 +1,29 @@ + + + + + +PHP Version:
+ +Diese Datei wurde geladen um:
+ + diff --git a/react-project/.dockerignore b/react-project/.dockerignore new file mode 100644 index 0000000..fa5cc20 --- /dev/null +++ b/react-project/.dockerignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +build +.git +.github +.gitignore +README.md diff --git a/react-project/Dockerfile b/react-project/Dockerfile new file mode 100644 index 0000000..06f3022 --- /dev/null +++ b/react-project/Dockerfile @@ -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;"] diff --git a/react-project/package.json b/react-project/package.json new file mode 100644 index 0000000..6a4b574 --- /dev/null +++ b/react-project/package.json @@ -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" + ] + } +} diff --git a/react-project/public/index.html b/react-project/public/index.html new file mode 100644 index 0000000..4ea0a6e --- /dev/null +++ b/react-project/public/index.html @@ -0,0 +1,15 @@ + + + + + + + + +Diese App läuft in einem Docker-Container
+ +Du hast den Button {count} mal geklickt
+ ++ Build-Zeit: {process.env.REACT_APP_BUILD_TIME || 'Unbekannt'} +
+