07 Docker安装mysql
搜索mysql镜像
[root@localhost test]# podman search mariadb
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/library/mariadb MariaDB is a community-developed fork of MyS... 3651 [OK]
docker.io docker.io/bitnami/mariadb Bitnami MariaDB Docker Image 124 [OK]
docker.io docker.io/linuxserver/mariadb A Mariadb container, brought to you by Linux... 162
docker.io docker.io/webhippie/mariadb Docker images for MariaDB 21 [OK]
docker.io docker.io/circleci/mariadb CircleCI images for MariaDB 3 [OK]
[root@localhost test]# podman pull mariadb
Trying to pull docker.io/library/mariadb...
Getting image source signatures
Copying blob ba34deb445c3 done
Copying blob e6ca3592b144 done
Copying blob 47b4f6570cf0 done
Copying blob 534a5505201d done
Copying blob 990916bd23bb done
Copying blob c62d6bd206a2 done
Copying blob 69df87d9330c done
Copying blob 6ab34d00af2f done
Copying blob 0222c6c4a452 done
Copying blob d9f0e67eb23f done
Copying blob 28b039c5139e done
Copying blob bb48a5d6fdc6 done
Copying config cbbff8572f done
Writing manifest to image destination
Storing signatures
cbbff8572fa8c9edd0d2f88f03f4dc6d0e6e0c6b03be8e97bae4efd8ba76f45f
[root@localhost test]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/simon_tomcat9 latest c379423344cf 26 hours ago 624 MB
docker.io/library/mariadb latest cbbff8572fa8 3 days ago 413 MB
docker.io/library/centos latest 0d120b6ccaa8 5 weeks ago 222 MB
运行镜像:
[root@localhost test]# mkdir -p /simon_data/mariadb/{conf,logs,data}
[root@localhost test]# podman run -p 23306:3306 --name mariadb \
-v /simon_data/mariadb/conf:/etc/mysql/conf \
-v /simon_data/mariadb/logs:/logs \
-v /simon_data/mariadb/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=wwwwww \
-d mariadb
b2030de64008247f395b967b05274551769bb6580ad21fbca078e044617c4784
[root@localhost test]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2030de64008 docker.io/library/mariadb:latest mysqld 57 seconds ago Up 56 seconds ago 0.0.0.0:23306->3306/tcp mariadb
测试:
[root@localhost conf]# podman exec -it b2030de64008 /bin/bash
root@b2030de64008:/#
root@b2030de64008:/#
root@b2030de64008:/# mysql -uroot -p'wwwwww'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> create database db01 default charset utf8;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> use db01;
Database changed
MariaDB [db01]> create table t_01 (id int(4) not null primary key,`name` varchar(32) default null);
Query OK, 0 rows affected (0.017 sec)
MariaDB [db01]> insert into t_01 values(1,'simon');
Query OK, 1 row affected (0.004 sec)
MariaDB [db01]> insert into t_01 values(2,'hukey');
Query OK, 1 row affected (0.003 sec)
MariaDB [db01]>
MariaDB [db01]> select * from t_01;
+----+-------+
| id | name |
+----+-------+
| 1 | simon |
| 2 | hukey |
+----+-------+
2 rows in set (0.001 sec)
# 备份
[root@localhost conf]# podman exec -it b2030de64008 /bin/bash -c ' exec mysqldump --all-databases -uroot -p'wwwwww'' > /simon_data/mariadb/data/all-database.sql
[root@localhost conf]#
[root@localhost conf]# ll !$
ll /simon_data/mariadb/data/all-database.sql
-rw-r--r-- 1 root root 4062659 Sep 20 09:50 /simon_data/mariadb/data/all-database.sql