Docker MariaDB Container ทดลองใช้งาน

ในการสร้าง container มันก็จะมี IP Address ประจำ container นั้นๆ  แต่ถ้าหากเราต้องการจะกำหนดหมายเลข IP Address เอง

[root@docker-test ~]# docker network create --subnet=192.168.100.0/24 mynetwork
8872bf61c8e3da662ce2a59ac77b8ac577e6385bb3409e8ca9014730affb1407
[root@docker-test ~]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
d3553315e0f1        bridge              bridge              local               
f89c7eb98e06        host                host                local               
8872bf61c8e3        mynetwork           bridge              local               
cca15c2e9e34        none                null                local

สร้าง MariaDB Container โดยที่กำหนด IP Adress ไปด้วย

[root@docker-test ~]# docker run --name mariadb-01  -v  /data/mysql:/var/lib/mysql -v /data/conf.d:/etc/mysql/conf.d -e  MYSQL_ROOT_PASSWORD=123456 --net mynetwork --ip 192.168.100.201 -d mariadb:10.1
df7fe01b9769240d6f21fcac2ca2e069d8f42f52658f92161338bb621d635456

ตรวจสอบ IP Address

[root@docker-test ~]# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadb-01
192.168.100.201
[root@docker-test ~]# ping 192.168.100.201
PING 192.168.100.201 (192.168.100.201) 56(84) bytes of data.
64 bytes from 192.168.100.201: icmp_seq=1 ttl=64 time=0.278 ms
64 bytes from 192.168.100.201: icmp_seq=2 ttl=64 time=0.414 ms

nmap ดูว่า เปิด port อะไรอยู่บ้าง

[root@docker-test ~]# nmap 192.168.100.201

Starting Nmap 6.40 ( http://nmap.org ) at 2016-12-03 14:03 ICT
Nmap scan report for 192.168.100.201
Host is up (0.000032s latency).
Not shown: 999 closed ports
PORT     STATE SERVICE
3306/tcp open  mysql
MAC Address: 02:42:C0:A8:0A:C9 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds

grant สิทธิให้ user sothorn

[root@docker-test ~]# docker exec -it mariadb-01 bash
root@df7fe01b9769:/# mysql -u root -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.19-MariaDB-1~jessie mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql-docker1> GRANT ALL PRIVILEGES ON *.* TO sothorn@"%" IDENTIFIED BY '12345678' WITH GRANT OPTION;             
Query OK, 0 rows affected (0.00 sec)

mysql-docker1> flush privileges;
Query OK, 0 rows affected (0.00 sec)

ทดลองเข้าใช้งานด้วย user sothorn

[root@docker-test ~]# mysql -u sothorn -h 192.168.100.201 -p12345678
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.19-MariaDB-1~jessie mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

อ้างอิง

Loading

Facebook Comments

Leave a reply