centos7 of docker docker installation and installation MySQL5.7

A, docker installation

1, see the kernel version must be higher than 3.10

$ uname -r

2, remove the old version

$ sudo yum remove docker*

3, install the necessary system tools

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

4, add the software source information (here pulling aliyun mirror)

$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5, yum update cache

$ sudo yum makecache fast

6, mounting Docker-ce

$ sudo yum -y install docker-ce

7, start the background service Docker

$ sudo systemctl start docker

8, hello-world test run

$ docker run hello-world

Two, docker installation MySQL5.7

1. Find available MySQL mirror

$ docker search mysql

2, mirrored pull MySQL 5.7

$ docker pull mysql:5.7

3, the pulled view mirror

$ docker images |grep mysql

4, create a directory mysql, used to store back-related stuff

$ mkdir mysql
$ cd mysql

5, MySQL create container

$ Docker run -p 3360: 3306 --name mymysql -v $ PWD / conf: /etc/mysql/conf.d -v $ PWD / logs: / logs -v $ PWD / data: / var / lib / mysql - 123456 = -d MySQL MYSQL_ROOT_PASSWORD E: 5.7 
# parameter Description
-p 3360: 3306: 3306 port mapping to the container port of the host 3360 (the first physical port unit, a second container port).
-v $ PWD / conf: /etc/mysql/conf.d: the conf / my.cnf under the current directory is mounted to the host vessel /etc/mysql/my.cnf.
-v $ PWD / logs: / logs : the logs directory under the current directory is mounted to the host container / logs.
-v $ PWD / data: / var / lib / mysql: a data directory of the host current directory is mounted to the container / var / lib / mysql.
-e MYSQL_ROOT_PASSWORD = 123456: initialize the root user's password.
-d: background container and return the container ID

6, check the running container

$ docker ps | grep mysql

Three, MySQL remote login

1, opening interactive mode terminal docker

$ docker exec -i -t mymysql /bin/bash

2, log on MySQL

$ mysql -u root -p

3. Enter the password into the MySQL grant

# - all permissions granted to user database of the user, allowing the user to remotely login user at any one IP, and set the root password is 123456 
> Grant All PRIVILEGES ON * * to 'user' @ '%' IDENTIFIED by. '123456'; 
> the flush privileges; 
> Exit;

4, exit docker terminal

$ exit

Guess you like

Origin www.cnblogs.com/zhaihongchang/p/11333184.html