docker application deployment---MySQL deployment configuration

1. Search for mysql mirror

docker search mysql

2. Pull the mysql image

 #安装5.6版本的Mysql,如果不加版本号,默认安装最新的mysql
docker pull mysql:5.6

3. Create a container and set port mapping and directory mapping

Create a mysql directory in the /root directory to store mysql data information

# 在/root目录下创建mysql目录用于存储mysql数据信息
mkdir ~/mysql
cd ~/mysql

Create a container and configure some corresponding parameters

docker run -id \
-p 3306:3306 \
--name=c_mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
mysql:5.6

● Parameter description:
○ -p 3306:3306: Map the container’s 3306 port to the host’s 3306 port.
○ -v $PWD/conf:/etc/mysql/conf.d: Mount conf/my.cnf in the current directory of the host to /etc/mysql/my.cnf in the container . Configuration directory
○ -v $PWD/logs:/logs: Mount the logs directory in the current directory of the host to /logs of the container. Log directory
○ -v $PWD/data:/var/lib/mysql: Mount the data directory in the current directory of the host to /var/lib/mysql of the container. Data directory
○ -e MYSQL_ROOT_PASSWORD=root: Initialize the password of the root user (set the password casually, don’t forget it)

4. Enter the container and operate mysql

docker exec –it c_mysql /bin/bash

5. Log in to mysql

mysql -uroot -proot

6. Use an external machine to connect to mysql in the container

I use the navicat tool in my windows system for remote testing to connect mysql in the docker container

Insert image description here

Insert image description here
Insert image description here
Insert image description here

Good luck, number reference, conclusion★,°:.☆( ̄▽ ̄)/$:.°★.


おすすめ

転載: blog.csdn.net/m0_63622279/article/details/134072935