docker安装mysql

2022-10-27 13:34:13 浏览数 (1)

# 1.拉取镜像

docker pull mysql:5.7

代码语言:javascript复制
[root@summer ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 ef08065b0a30        2 months ago        448MB

# 2.创建mysql的映射目录

代码语言:javascript复制
[root@summer ~]# mkdir -p /root/mysql/data /root/mysql/logs /root/mysql/conf
[root@summer ~]# cd mysql/conf/
[root@summer conf]# touch my.cnf
[root@summer conf]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 10 09:31 my.cnf
[root@summer conf]# pwd
/root/mysql/conf

# 3.创建容器,将数据,日志,配置文件映射到本机

代码语言:javascript复制
[root@summer conf]# docker run -p 3306:3306 --name mysql -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/logs:/logs -v /root/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=hadoop -d mysql:5.7
5925d95eb8c70df57a9017ea28d97789ae2639b61a6e42375673146ec70fc89f
[root@summer conf]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                               NAMES
5925d95eb8c7        mysql:5.7           "docker-entrypoint.s…"   About a minute ago   Up 59 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
  • -d: 后台运行容器
  • -p 将容器的端口映射到本机的端口
  • -v 将主机目录挂载到容器的目录
  • -e 设置参数

# 4.验证

0 人点赞