docker in the build MySQL service

docker constructed MySQL Service

Container running MySQL, implemented in the database can be connected to external service CRUD. Claim:

  1. After the host system reboot is complete database service starts automatically

  2. After re-create the MySQL container, raw data can also be used (ie delete container data is not lost)

 

Implementation:

  1. Use docker get MySQL mirror

    docker pull ecr.eisoo.com:5000/mysql:5.7.27

[root@localhost ~]# docker pull ecr.eisoo.com:5000/MySQL:5.7.27
5.7.27: Pulling from MySQL
Digest: sha256:b16d058ac835a0a087d4e42a5c200abc2a4936ec73ff7a427b28257f66bb5c04
Status: Image is up to date for ecr.eisoo.com:5000/MySQL:5.7.27
ecr.eisoo.com:5000/MySQL:5.7.27

2. Profiles

[root@localhost ~]# mkdir my
[root@localhost ~]# mkdir -p docker/MySQL/data docker/MySQL/conf
  • My new directory in the root directory, and create docker / mysql / data directory and docker / mysql / conf directory

[client]
port=3306
default-character-set=utf8
[MySQL]
default-character-set=utf8
[MySQLd]
character_set_server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 配置大小写不敏感
lower_case_table_names=1
  • Enter the root / my / docker / mysql / conf directory, create mysql my.cnf file and configure

3. directory, file permissions

[root@localhost conf]# chmod -R 777 /root/my/docker/mysql
[root@localhost conf]# cd /root/my/docker/mysql/conf
[root@localhost conf]# chmod 644 my.cnf

4. Run vessel and remounting

[root@localhost data]# systemctl enable docker.service
  • Set docker boot from the start, when the MySQL start-up to achieve the docker also start

mysql[root@localhost conf]# docker run -d -it --restart=always --name mysqlL -p 3308:3306 -e mysql_ROOT_PASSWORD=driver --privileged=true -v /root/my/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /root/my/MySQL/data:/var/lib/mysql -v /root/my/docker/MySQL/logs:/var/log/mysql ecr.eisoo.com:5000/mysql:5.7.27
  • --name container specified name

  • --restart = always set the MySQL service from the start

  • -e MySQL_ROOT_PASSWORD = driver set the root password for MySQL

  • -p port mapping

  • -v mount host directories to delete container after container in order to achieve data is not lost

5 into the container

[root@localhost data]# docker exec -it mysql bash
  • CRUD operations performed

mysql> create database test;
mysql> use test;
mysql> create table test(name varchar(20),age int);
mysql> insert test values('april',20),('tom',18),('mary',21);
mysql> select * from test;
+-------+------+
| name | age |
+-------+------+
| april |   20 |
| tom   |   18 |
| mary |   21 |
+-------+------+
3 rows in set (0.00 sec)
mysql> update test set name='lisa' where name='mary' ;
mysql> select * from test;
+-------+------+
| name | age |
+-------+------+
| april |   20 |
| lisa |   21 |
+-------+------+
2 rows in set (0.00 sec)

6. Remove the container

[root@localhost data]# docker stop mysql
[root@localhost data]# docker rm mysql

 

Guess you like

Origin www.cnblogs.com/Aprilnn/p/11276136.html