docker中创建mysql容器,远程数据库

1.拉取合适版本的镜像

[root@VM-0-17-centos ~]# docker pull mysql:5.7.31
5.7.31: Pulling from library/mysql
bf5952930446: Already exists 
8254623a9871: Pull complete 
938e3e06dac4: Pull complete 
ea28ebf28884: Pull complete 
f3cef38785c2: Pull complete 
894f9792565a: Pull complete 
1d8a57523420: Pull complete 
5f09bf1d31c1: Pull complete 
1b6ff254abe7: Pull complete 
74310a0bf42d: Pull complete 
d398726627fd: Pull complete 
Digest: sha256:da58f943b94721d46e87d5de208dc07302a8b13e638cd1d24285d222376d6d84
Status: Downloaded newer image for mysql:5.7.31
docker.io/library/mysql:5.7.31

2.启动docker,配置数据卷

[root@VM-0-17-centos ~]# docker container run -p 3306:3306 --mount source=mysql,destination=/var/lib/mysql -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=password --name xuyaomysql -d mysql
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
bf5952930446: Already exists 
8254623a9871: Already exists 
938e3e06dac4: Already exists 
ea28ebf28884: Already exists 
f3cef38785c2: Already exists 
894f9792565a: Already exists 
1d8a57523420: Already exists 
6c676912929f: Pull complete 
ff39fdb566b4: Pull complete 
fff872988aba: Pull complete 
4d34e365ae68: Pull complete 
7886ee20621e: Pull complete 
Digest: sha256:c358e72e100ab493a0304bda35e6f239db2ec8c9bb836d8a427ac34307d074ed
Status: Downloaded newer image for mysql:latest
dfb00e6b835dbc5632337fc59954b164f5c07856f40b5371c39425f9f45f3b09

3.运行mysql

[root@VM-0-17-centos ~]# docker run --name docker_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
49a449d43748e919430fcbb17cd4d02d6fd1369973108f52c5ebcf411a49eddc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值