Mysql single instance installation-docker articles

1. Install Docker
CentOS 7 Install Docker: https://docs.docker.com/engine/install/centos/
1.1, uninstall the old version of Docker
yum remove -y docker docker-client docker-client-latest docker-common
docker -latest docker-latest-logrotate docker-logrotate
docker-selinux docker-engine-selinux docker-engine
Insert picture description here
1.2, execute the following installation command to install the dependency package
[root@centos7 ~] yum install -y yum-utils device-mapper-persistent- data lvm2
[root@centos7 ~] sudo yum-config-manager
–add-repo
https://download.docker.com/linux/centos/docker-ce.repo

[root@centos7 ~] yum -y install docker-ce docker-ce-cli containerd.io

[root@centos7 ~]# docker ps --查看docker
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? --docker没有启动

1.3、启动 Docker
[root@centos7 ~]#systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@centos7 ~]#systemctl start docker
[root@centos7 ~]#systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-01-16 18:47:43 EST; 6s ago
Docs: https://docs.docker.com
Main PID: 2435 (dockerd)
Memory: 45.1M
CGroup: /system.slice/docker.service
└─2435 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.051980834-05:00” level=info msg="ccResolverWrapper: …e=grpc
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.051989827-05:00” level=info msg="ClientConn switchin…e=grpc
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.077331225-05:00” level=info msg=“Loading containers: start.”
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.382655173-05:00” level=info msg=“Default bridge (doc…dress”
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.449861379-05:00” level=info msg=“Loading containers: done.”
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.463137686-05:00” level=warning msg="Not using native…erlay2
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.463311349-05:00” level=info msg=“Docker daemon” comm…0.10.2
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.463380194-05:00” level=info msg=“Daemon has complete…ation”
Jan 16 18:47:43 centos7 systemd[1]: Started Docker Application Container Engine.
Jan 16 18:47:43 centos7 dockerd[2435]: time=“2021-01-16T18:47:43.493313812-05:00” level=info msg=“API listen on /var/…sock”
Hint: Some lines were ellipsized, use -l to show in full.

[root@centos7 ~]# docker ps --View container
[root@centos7 ~]# docker version --View version
[root@centos7 ~]# docker info --View version

1.4.docker Specify the container ip
when creating a container Docker uses the bridge network by default when creating a container, and assigns the ip by itself, not allowing you to specify it yourself.
In actual deployment, we need to specify the container ip and do not allow it to allocate ip by itself, especially when building a cluster, a fixed ip is necessary.
We can create our own bridge network: mynet. When creating the container, specify the network as mynet and specify the ip.

[root@docker ~]# docker network ls – view network mode
[root@docker ~]# docker network create --driver bridge --subnet=172.18.12.0/16 --gateway=172.18.1.1 mynet – create a new one bridge网络
[root@docker ~]# docker network inspect mynet --View network information

二、Mysql安装
[root@centos7 ~]# docker search mysql
[root@centos7 ~]# docker pull mysql:5.7.30
[root@centos7 ~]# docker pull mysql:8.0.20


#The host executes the following command mkdir -p /usr/local/mysql5730/
mkdir -p /usr/local/mysql8020/

【5.7.30版本】
docker run -d --name mysql5730 -h mysql5730
-p 233:22 -p 3607:3306
–network=mynet --ip 172.18.12.1
-v /sys/fs/cgroup:/sys/fs/cgroup
-v /usr/local/mysql5730/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=root -e TZ=Asia/Shanghai
mysql:5.7.30

[root@centos7 ~]# docker update --restart=always mysql5730 --start at boot
[root@centos7 ~]# docker exec -it mysql5730 bash

【8.0.20版本】
docker run -d --name mysql8020 -h mysql8020
-p 234:22 -p 3608:3306
–network=mynet --ip 172.18.12.2
-v /sys/fs/cgroup:/sys/fs/cgroup
-v /usr/local/mysql8020/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=root -e TZ=Asia/Shanghai
mysql:8.0.20

[root@centos7 ~]# docker update --restart=always mysql8020 --start at boot
[root@centos7 ~]# docker exec -it mysql8020 bash

Note: The above passwords are all root

Guess you like

Origin blog.csdn.net/weixin_41645135/article/details/115025333