Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Forked from jcavat/Dockerfile
Last active March 14, 2024 10:52
Show Gist options
  • Save Beyarz/674b24d03614fde205a38f449800857a to your computer and use it in GitHub Desktop.
Save Beyarz/674b24d03614fde205a38f449800857a to your computer and use it in GitHub Desktop.
Updated version of: docker-compose with Php 7.2.6, Mysql 8.0.16, Phpmyadmin 4.8 & Apache
Create a directory with the following structure:
├── docker-compose.yml
├── Dockerfile
├── dump
│   └── myDb.sql
└── www
└── index.php
version: "3"
services:
www:
build: .
ports:
- "8001:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
db:
image: mysql:8.0.16
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.8
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
FROM php:7.2.6-apache
RUN docker-php-ext-install mysqli
<?php
$conn = mysqli_connect('db', 'user', 'test', 'myDb', 3306);
mysqli_set_charset($conn, "utf8");
$query = 'SELECT * From Person';
$result = mysqli_query($conn, $query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<style>body{font-family:Nunito,sans-serif;min-height:90vh;align-items:center;justify-content:center;display:flex}</style>
</head>
<body>
<p>
<?php
while ($value = $result->fetch_array(MYSQLI_ASSOC)) {
foreach ($value as $element) {
echo ' - ' . $element;
}
}
$result->close();
mysqli_close($conn);
?>
-
</p>
</body>
</html>
CREATE DATABASE IF NOT EXISTS myDb;
USE myDb;
SET
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET
time_zone = "+01:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
CREATE TABLE `Person` (
`id` int(11) NOT NULL,
`name` varchar(20) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET = latin1;
INSERT INTO
`Person` (`id`, `name`)
VALUES
(1, 'Conf'),
(2, 'Nipsu'),
(3, 'Beyar');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
@gardenboi
Copy link

Thank you, it's been really daunting trying to set this stuff alone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment