https:
https:
เคยลง image ทำ webserver บริการ php + mysql ไว้
d:/thaiall.com/joomla
[Dockerfile]
[docker-compose.yml]
--link [name or id]:alias
docker run -d -p 127.0.0.1:80:5000/udp training/webapp python app.py
[Hyper-v Manager]
docker-machine ip
default
(ไม่พบใน win 10 pro)
docker-machine ls (ไม่พบ
default
)
docker-machine create --driver hyperv vm (win 10 pro)
สร้าง virtual
switch
ตาม https:
เปิด Hyper-v Manager
1. MAKE SURE HYPER-V IS ENABLED
2. SET UP A NEW EXTERNAL NETWORK SWITCH (OPTIONAL)
3. REBOOT
4. CREATE THE NODES WITH DOCKER MACHINE AND THE MICROSOFT HYPER-V DRIVER
PS admin> docker-machine create -d hyperv --hyperv-virtual-
switch
"Primary Virtual Switch"
worker1
172.50.1.90
PS admin> docker-machine create -d hyperv --hyperv-virtual-
switch
"Primary Virtual Switch"
default
PS admin> docker-machine ls (พบ worker1)
PS admin> docker-machine stop worker1
PS admin> docker-machine start
default
===
0. clear
docker rm -f $(docker ps -aq)
docker rmi $(docker images -q) -f
===
1. สร้างแฟ้ม Dockerfile ใน d:\thaiall.com\joomla
FROM php:7.3.1-apache
RUN apt-get update
RUN apt-get install -y vim
RUN docker-php-ext-install pdo pdo_mysql mysqli
#FROM mariadb:10.4.1
#COPY myjoomla.sql /docker-entrypoint-initdb.d/
#RUN cp -r /var/lib/mysql /var/lib/mysql-no-volume
#CMD ["--datadir", "/var/lib/mysql-no-volume"]
2. สร้างแฟ้ม docker-compose.yml ใน d:\thaiall.com\joomla
https:
version:
'3'
services:
php-apache:
image: php:7.3.1-apache
build:
context: .
ports:
- 8080:80
volumes:
- /c/Users/acer/joomla:/
var
/www/htmltmp
networks:
-
default
links:
-
'maria-db'
maria-db:
image: mariadb:10.4.1
ports:
-
"6603:3306"
volumes:
- /c/Users/acer/joomla/myjoomlasql:/docker-entrypoint-initdb.d
environment:
TZ:
"Asia/Bangkok"
MYSQL_ALLOW_EMPTY_PASSWORD:
"no"
MYSQL_ROOT_PASSWORD:
"myrootpassword"
MYSQL_USER:
"myuser"
MYSQL_PASSWORD:
"myuserpassword"
MYSQL_DATABASE:
"myjoomla"
networks:
-
default
3. สร้าง container
3.1 docker pull hello-world
3.2 docker build . (ใน d:\thaiall.com\joomla)
--- รอ php
--- Dockerfile
3.3 docker-compose up (ถ้ามี container อยู่ ก็เพียงแต่ start container ถ้าไม่มีก็เพียงแต่สร้าง container)
--- รอ mariadb
--- docker-compose.yml
--- Dockerfile
3.4 docker ps
4. mariadb
docker inspect bbbc537a55df
docker exec -it bbbc537a55df /bin/bash
ls /docker-entrypoint-initdb.d/dump.sql
บน win 10 home
docker exec -it bbbc537a55df /usr/bin/mysql -uroot -p (กำลังประมวลผล sql)
docker exec -it bbbc537a55df /usr/bin/mysql -uroot -pmyrootpassword
use myjoomla; show tables;
บน win 10 pro
docker exec -it bbbc537a55df /usr/bin/mysql -uroot -pmyrootpassword
show databases;
ไม่ต้องใช้คำสั่งนี้เลย source /docker-entrypoint-initdb.d/dump.sql;
5. stop & start
Ctrl-C : docker-compose up
docker start bbbc537a55df (mariadb:10.4.1)
docker start 07c7fc66e429 (php:7.3.1-apache)
docker inspect 07c7fc66e429
6. backup dump.sql
docker exec -it bbbc537a55df /bin/bash
ls -al /docker-entrypoint-initdb.d/dump.sql
cp /docker-entrypoint-initdb.d/dump.sql /home/dump.sql
7. php
docker start 07c7fc66e429
docker exec -it 07c7fc66e429 /bin/bash
cd ../htmltmp
cp -r * ../html
echo
"<?php if(!"
"session_start()){ echo 0; } else { echo 1;} phpinfo(); ?>"
>x1.php
echo
"<?php phpinfo(); ?>"
>x2.php
cd libraries/joomla/session/handler/
8. ทดสอบ
http:
http:
Warning: session_start(): Failed to read session data: user (path: )
in
/
var
/www/html/libraries/joomla/session/handler/native.php on line 260
Error: Failed to start application: Failed to start the session
docker exec -it 07c7fc66e429 /bin/bash
#if (!session_start())
#{
# throw new RuntimeException('Failed to start the session');
#}
if
(session_start()) {}
else
{
throw
new
RuntimeException(
'Failed to start the session'
);
}
cp /
var
/www/htmltmp/libraries/joomla/session/handler/native-remark-260.php /
var
/www/html/libraries/joomla/session/handler/native.php
cp /
var
/www/htmltmp/libraries/joomla/session/handler/native.php /
var
/www/html/libraries/joomla/session/handler/native.php
public $host =
'192.168.99.100:6603'
;
public $user =
'root'
;
public $password =
''
;
public $host =
'maria-db'
;
public $user =
'root'
;
public $password =
'myrootpassword'
;
$link = mysqli_connect(
"maria-db"
,
"root"
,
"myrootpassword"
,
"myjoomla"
);
if
(!$link) {
echo
"Error: Unable to connect to Database"
. PHP_EOL;
echo
"Debugging errno: "
. mysqli_connect_errno() . PHP_EOL;
echo
"Debugging error: "
. mysqli_connect_error() . PHP_EOL;
}
else
{ echo
"connect : ok"
; }
=============
phpMyAdmin
cp -r * ../../html/phpMyAdmin
config.inc.php
cp /
var
/www/htmltmp/phpMyAdmin/config.inc.php /
var
/www/html/phpMyAdmin/config.inc.php
cp config.inc.php ../../html/phpMyAdmin
mkdir ../../html/phpMyAdmin/tmp
chmod 777 ../../html/phpMyAdmin/tmp
The $cfg[
'TempDir'
] (./tmp/) is not accessible. phpMyAdmin is not able to cache templates and will be slow because of
this
.
พบปัญหา ฐานข้อมูล
Error: Failed to start application: Could not connect to MySQL server.
ยกเลิก readonly configuration.php เพื่อแก้ไขก่อน
public $host =
'localhost:6603'
;
public $user =
'root'
;
public $password =
'myrootpassword'
;
public $db =
'myjoomla'
;
cp /
var
/www/htmltmp/configuration.php /
var
/www/html/configuration.php
Warning: mysqli_connect(): (HY000/1130): Host
'172.17.0.1'
is not allowed to connect to
this
MariaDB server
echo gethostbyname(
"maria-db"
);
$link = mysqli_connect(
"maria-db"
,
"root"
,
"myrootpassword"
,
"myjoomla"
);
if
(!$link) {
echo
"Error: Unable to connect to Database"
. PHP_EOL;
echo
"Debugging errno: "
. mysqli_connect_errno() . PHP_EOL;
echo
"Debugging error: "
. mysqli_connect_error() . PHP_EOL;
}
else
{ echo
"connect : ok"
; }
echo
"phpMyAdmin"
;
phpinfo();
cp /
var
/www/htmltmp/phpinfo.php /
var
/www/html/phpinfo.php
7. Commit php
docker commit 07c7fc66e429 thaiall/php:7.3.1-apache-myjoomla.1
docker run -p 8080:80 -d --name php_web1 thaiall/php:7.3.1-apache-myjoomla.1
docker login --username=thaiall
docker push thaiall/php:7.3.1-apache-myjoomla.1
* The push refers to repository [docker.io/thaiall/php]
https:
8. Commit mariadb
docker commit bbbc537a55df thaiall/mariadb:10.4.1-myjoomla.1
docker run -p 6603:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=myrootpassword -d thaiall/mariadb:10.4.1-myjoomla.1
docker login --username=thaiall (tenten)
docker push thaiall/mariadb:10.4.1-myjoomla.1
https:
* The push refers to repository [docker.io/thaiall/mariadb]
9. run อีกเครื่องหนึ่ง
docker inspect 36ed57667a95 (mariadb) 172.17.0.3
docker exec -i -t 36ed57667a95 /bin/bash
docker exec -it 36ed57667a95 /usr/bin/mysql -uroot -pmyrootpassword
use myjoomla;
show tables;
source /home/dump.sql;
docker inspect 253b66ef3f39 (php)
docker exec -i -t 253b66ef3f39 /bin/bash
phpMyAdmin
config.inc.php
$cfg[
'Servers'
][$i][
'host'
] =
'172.17.0.3'
;
joomla
configuration.php
public $host =
'172.17.0.3'
;
vim libraries/joomla/session/handler/native.php start & next
$ docker run -p 6603:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=myrootpassword -d thaiall/mariadb:10.4.1-myjoomla.1
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: cannot mount volume over existing file, file exists /mnt/sda1/
var
/lib/docker/overlay2/83b740a4c844ed2a5cf104cdb96ac679a7279ff7a22b361819f7a0b8fba88f7f/merged/mnt/myjoomla.sql.
See
'C:\Program Files\Docker Toolbox\docker.exe run --help'
.
docker run -p 8080:80 -d --name=php_web1 thaiall/php:7.3.1-apache-myjoomla.1
docker run -p 6603:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=myrootpassword -d thaiall/mariadb:10.4.1-myjoomla.1
docker run -it -e MYSQL_ROOT_PASSWORD=example mysql:5.7 --datadir=/
var
/lib/mydata
หากปรับใช้ docker-compose build
Pulling maria-db (mariadb:10.4.1)
Pulling php (php:7.3.1-apache)
maria-db_1 | 2019-02-17 15:21:37 0 [Note] Added
new
Master_info
''
to hash table
4. docker images
พบ Repository : php และ Tag : 7.3.1-apache มี Image id : xxxxxxx ขนาด 378MB
5. คำสั่ง docker run
https:
c:\users\acer\joomla
docker run -v /c/Users/my-account:container-path
https:
การ mount ไม่ใช่การ copy แต่เป็นการอ้างอิงไปแบบ soft link
docker run --rm -p 8080:80 -d --name=php_web php:7.3.1-apache
docker run --rm -p 8080:80 -d --name=php_web -v /c/Users/acer/joomla:/
var
/www/html php:7.3.1-apache
docker run --rm -p 8080:80 -d --name=php_web -v
"./varwwwhtml"
:/
var
/www/html php:7.3.1-apache
docker run --rm -p 8080:80 -d --name=php_web -v
"$PWD"
:/
var
/www/html php:7.3.1-apache
docker run -d -p 8080:80 --mount type=bind,source=
"$(pwd)"
,target=/
var
/www/html php:7.3.1-apache
docker run php:7.3.1-apache env
--rm คือ ลบ container ทิ้ง เมื่อทำงานเสร็จ
ทดสอบ
ไม่ ok บน win 10 home เมื่อใช้ docker run --rm -v
"/c/users"
:/data alpine ls
ไม่ ok บน win 10 home เมื่อใช้ docker run --rm -v
"/c/Windows"
:/data alpine ls
ok บน win 10 home เมื่อใช้ docker run --rm -v
"/c/Users"
:/data alpine ls
ok บน win 10 home เมื่อใช้ docker run --rm -v /c/Users:/data alpine ls
ok บน win 10 home เมื่อใช้ docker run --rm -v /c/Users/acer/joomla:/data alpine ls
6. docker run -p 6603:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=myrootpassword -d mariadb:10.4.1
7. docker rm -f $(docker ps -aq) สั่ง stop และ remove container ทั้งหมด
8. docker container list --all แสดงรายการทั้งหมดทั้งที่ exited และ running
9. chrome : http:
10. docker exec -it [container id] /bin/bash
docker exec -it 56afa68c75fc /bin/bash
# cd /var/www/html
# ls
# ls >index.html
docker run -p 6603:3306 --name mariadb -e MYSQL_ROOT_PASSWORD=myrootpassword -d mariadb:10.4.1
docker ps
docker exec -it c137efe362a0 mysql -uroot -pmyrootpassword (just enter)
show databases;
create database myjoomla;
use myjoomla;
SELECT host, user FROM mysql.user;
ALTER USER
'root'
@
'%'
IDENTIFIED BY
'myrootpassword'
;
ALTER USER
'root'
@
'localhost'
IDENTIFIED BY
'myrootpassword'
;
GRANT ALL PRIVILEGES ON *.* TO
'root'
@
'%'
WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO
'root'
@
'localhost'
WITH GRANT OPTION;
Warning: mysqli_connect(): (HY000/2002): Connection refused
in
/
var
/www/html/x.php on line 1
error
in
toolbox : docker exec -it ada917d84f58 mysql -uroot -pmyrootpassword myjoomla < /d/myjoomla.sql
error
in
toolbox : winpty docker exec -it ada917d84f58 mysql -uroot -pmyrootpassword myjoomla < /d/myjoomla.sql
error
in
ps(admin) : docker exec -it ada917d84f58 mysql -uroot -pmyrootpassword myjoomla < d:\myjoomla.sql
error
in
dos : docker exec -it ada917d84f58 mysql -uroot -pmyrootpassword myjoomla < d:\myjoomla.sql
error
in
toolbox : cat myjoomla.sql | docker exec -it ada917d84f58 mysql -uroot -pmyrootpassword myjoomla
ok : toolbox : docker exec -i 2ae5c722d3ec /usr/bin/mysql -uroot -pmyrootpassword myjoomla < myjoomla.sql
c:\xampp\mysql\bin\mysql -u root -p testj < mydata.sql
SELECT
sum(((data_length + index_length) / 1024 / 1024)) `Size
in
MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length);
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size
in
MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
11. Create docker image from container
https:
mkdir /
var
/www/myjoomla
cd /
var
/www/html
cp -Rf * /
var
/www/myjoomla
mv -f /
var
/www/myjoomla /
var
/www/html
----
16ff163f4ee2 php:7.3.1-apache-myjoomla.1
6c22375e6541 mariadb:10.4.1-myjoomla.1
docker container ls -a
---
docker commit 16ff163f4ee2 thaiall/php:7.3.1-apache-myjoomla.2
docker login --username=thaiall
docker push thaiall/php:7.3.1-apache-myjoomla.2
* The push refers to repository [docker.io/thaiall/php]
https:
---
docker commit 6c22375e6541 thaiall/mariadb:10.4.1-myjoomla.2
docker login --username=thaiall
docker push thaiall/mariadb:10.4.1-myjoomla.2
https:
* The push refers to repository [docker.io/thaiall/mariadb]
---
https:
https:
docker run -itd --name=busybox3 thaiall/busybox_two:1.4
docker exec -it busybox3 three
https: