Skip to content

Instantly share code, notes, and snippets.

@sweikenb
Created January 30, 2019 15:01
Show Gist options
  • Save sweikenb/7b3d167be2c2c9e7b501c1494e557f94 to your computer and use it in GitHub Desktop.
Save sweikenb/7b3d167be2c2c9e7b501c1494e557f94 to your computer and use it in GitHub Desktop.
Simple LAMP Docker Setup
version: '3'
services:
php-apache:
build: ./
ports:
- 8080:80
volumes:
- ./:/var/www/html:z
links:
- 'mariadb'
mariadb:
image: mariadb:10.1
volumes:
- mariadb:/var/lib/mysql
ports:
- 33060:3306
environment:
TZ: "Europe/Berlin"
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_USER: 'dev'
MYSQL_PASSWORD: 'dev'
MYSQL_DATABASE: 'dev'
volumes:
mariadb:
FROM php:7.2.1-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli
<?php
try {
$dbh = new PDO('mysql:host=mariadb;dbname=dev', 'dev', 'dev');
$dbh->query('CREATE TABLE IF NOT EXISTS test_table (Name VARCHAR(64) NOT NULL)');
foreach ($dbh->query('SHOW tables;') as $row) {
echo '<pre>';
print_r($row);
echo '</pre>';
echo '<hr>';
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment