Use docker rapid deployment mysql container
Installation docker
# 安装Docker-CE yum install -y yum-utils device-mapper-persistent-data lvm2 # 增加最新版本的Docker安装仓库 yum-config-manager --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo # 安装Docker-CE版本 sudo yum install -y docker-ce docker-ce-cli containerd.io # 启动docker sudo systemctl enable docker # 允许开机启动 sudo systemctl start docker
Mysql download image files
# 查看所需镜像版本,这里是查看mysql 5.6版本 # 默认会下载5.6里面最新的版本 docker search mysql:5.6 # 下载对应版本的mysql,是用mysql:版本号 docker pull mysql:5.6
Profiles
[client] default-character-set=utf8 [mysqld] character-set-server=utf8 default-storage-engine=INNODB collation-server=utf8_general_ci pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log [mysql] default-character-set=utf8
After storage path, you can modify, amend remember the path to change the startup parameters of the container
/home/docker-conf/mysql/cnf/my.cnf
Start command vessel
docker run -it \ --name=mysql \ # 如果更改了存放路径,记得修改下面的配置参数 \ -v /home/docker-conf/mysql/cnf/:/etc/mysql/conf.d \ -e MYSQL_ROOT_PASSWORD=123456 \ # --ip 127.0.0.1 \ -p 3306:3306 \ -d mysql:5.6 \ /bin/bash
Interpretation of parameters
--name custom name, two
-
-v file mount directory
:
In front of the host computer is a directory, the directory is behind the container-e set the initial password mysql, but seemingly useless
-p port mapping
:
Is mapped to a port on the front of the host, it is behind the container portSuch as mysql default port is 3306, meaning that the mapping mysql container port 3306 to port 3306 of the host,
Mysql container 3306 to be accessed to access the host port via
-d represents the background
The latter is the image name and version number
Into the interior of the container
docker attach mysql # 或者 docker exec -it 容器名或者container ID
Mysql command execution
usermod -d /var/lib/mysql/ mysql
Start mysql
service mysql start
Use mysql
mysql -uroot -p 提示输入密码。直接回车.
Other commands
Because the Container ID is achieved by a hash algorithm, so that under normal circumstances is unique ID for each container, in order to facilitate the operation, the former will be able to take several, no value, and the same number of other containers taken long can be repeated
# 比如
container ID name
a12345 mysql01
a11234 centos7.6
b12345 mysql02
b23456 centos6.8
c23456 redis
# 可以这么来取
docker start a12
# 也可以这样
docker start mysql01
# 更简单的
docker start c # 因为c开头的就一个
View container running
docker ps
View all containers (including not running)
docker ps -a
Start container
docker start 容器名或container ID
Stop the container
docker stop 容器名或container ID
Delete container
docker rm container ID # 注意:运行的容器一定要先stop,再rm
View image files
docker images