name$ pwd
/c/Program Files/Docker Toolbox
$ cd
$ pwd
/c/Users/ACER
$ mkdir website1 & cd website1
$ vi docker-compose.yml (or notepad)
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: myrootpassword
MYSQL_DATABASE: mydb
MYSQL_USER: myuser
MYSQL_PASSWORD: myuserpassword
ports:
- "6603:3306"
web:
image: php:7.2.2-apache
container_name: php_web
depends_on:
- db
volumes:
- ./php/:/var/www/html/
ports:
- "8080:80"
stdin_open: true
tty: true
$ mkdir php
$ cd php
$ echo "<?php phpinfo(); ?>">index.php
$ cat index.php
$ cd ..
$ docker-compose up -d (download images นานมาก)
$ docker-machine ip default
192.168.99.100
$ start http://$(docker-machine ip default):8080/index.php
$ start mysql://myuser:myuserpassword@$(docker-machine ip default):6603/mydb
$ cd php
$ echo $(date +"%m_%d_%Y")>>index.php
$ echo $(date +"%m_%d_%Y")>>test.php
$ start http://$(docker-machine ip default):8080/test.php
$ docker container ls -all |grep php
613c9d97bd93
$ docker exec -t -i 613c9d97bd93 /bin/bash
# ls index.php
$ docker images | grep mysql
$ docker ps -a |grep mysql
6aae0cda606e
$ docker exec -i 6aae0cda606e mysql -umyuser -pmyuserpassword <<< "show databases;"
$ docker exec -i 6aae0cda606e mysql -uroot -pmyrootpassword <<< "show databases;"
https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/docker-mysql-getting-started.html
docker exec -it 5f71c645b823 mysql -uroot -pmyrootpassword
mysql>
create database mydb;
use mydb;
create table a (a1 int, a2 char(20));
insert into a values (1, "abc");
insert into a values (2, "def");
select * from a;
$ cat my.php
echo "<?php" '$link' " = mysqli_connect('172.17.0.2', 'root', 'myrootpassword', 'myjoomla'); ?>" > x.php
echo "<?php" '$link' " = mysqli_connect('maria-db', 'root', 'myrootpassword', 'myjoomla'); ?>" > x.php
$link = mysqli_connect("172.18.0.2", "root", "myrootpassword", "myjoomla");
$link = mysqli_connect("172.17.0.2", "root", "myrootpassword", "myjoomla");
$conn = mysqli_connect("maria-db", "root", "myrootpassword", "mydb");
$conn = mysqli_connect("192.168.99.100:6603", "root", "myrootpassword", "mydb");
if (!$conn) { die(mysqli_connect_error()); }
if ($result = mysqli_query($conn,"select * from a")) {
while($row = mysqli_fetch_assoc($result)) {
echo $row["a1"] . $row["a2"]. "<br/>";
}
}
mysqli_close($conn);
Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html
$ docker container ls -all |grep php
613c9d97bd93
$ docker exec -t -i 613c9d97bd93 /bin/bash
# docker-php-ext-enable mysqli
# docker-php-ext-install mysqli
#exit
$ docker commit -p 613c9d97bd93 php:7.2.2-apache-mysqli
$ docker ps -a
$ docker stop [container-id]
$ docker rm -f $(docker ps -aq)
$ docker run --rm -p 8080:80 -d --name=php_web -v /c/Users/ACER/website1/php/:/var/www/html php:7.2.2-apache-mysqli
$ docker run -p 6603:3306 --name mysql573 -e MYSQL_ROOT_PASSWORD=myrootpassword -d mysql:5.7
https://alysivji.github.io/php-mysql-docker-containers.html
https://qiita.com/kazuma1989/items/e08e8475fc5126f2363f (Mingw64)
https://medium.com/@meeramarygeorge/create-php-mysql-.. (ติดตั้ง ubuntu ด้วย)