Centos7服务器中Docker启动mysql容器

首先,配置配置 Docker 加速器:由于国外镜像下载缓慢,咱们中国人用自己国内镜像,这里,博主用的是DaoCloud镜像加速:

# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://271adcfb.m.daocloud.io

该脚本可以将 –registry-mirror 加入到你的 Docker 配置文件 /etc/sysconfig/docker
如果没有/etc/sysconfig/docker这个配置文件
1、# vim /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
ExecStart=/usr/bin/dockerd $OPTIONS
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
MountFlags=slave

[Install]
WantedBy=multi-user.target

2、# vim /etc/sysconfig/docker

# /etc/sysconfig/docker# Modify these options if you want to change the way the docker daemon runs
OPTIONS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
DOCKER_CERT_PATH=/etc/docker

# If you want to add your own registry to be used for docker search and docker
# pull use the ADD_REGISTRY option to list a set of registries, each prepended
# with --add-registry flag. The first registry added will be the first registry
# searched.
# ADD_REGISTRY='--add-registry registry.access.redhat.com'

# If you want to block registries from being used, uncomment the BLOCK_REGISTRY
# option and give it a set of registries, each prepended with --block-registry
# flag. For example adding docker.io will stop users from downloading images
# from docker.io
# BLOCK_REGISTRY='--block-registry'

# If you have a registry secured with https but do not have proper certs
# distributed, you can tell docker to not look for full authorization by
# adding the registry to the INSECURE_REGISTRY line and uncommenting it.
 INSECURE_REGISTRY='--insecure-registry dl.dockerpool.com:5000'

# On an SELinux system, if you remove the --selinux-enabled option, you
# also need to turn on the docker_transition_unconfined boolean.
# setsebool -P docker_transition_unconfined 1

# Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp

# Controls the /etc/cron.daily/docker-logrotate cron job status.
# To disable, uncomment the line below.
# LOGROTATE=false

3、重启docker

# systemctl daemon-reload
# systemctl restart docker
此时,可以下载镜像了:
# docker pull mysql

下载完成后:

# docker ps -a

查看镜像信息

创建外部数据挂载点:

# sudo mkdir -p /var/docker_data/mysql/data
# sudo chmod 775 -R /var/docker_data/mysql/

启动Mysql容器
通过-e参数可以设定一下Mysql服务端的参数,这里设置了root的密码:123456

# docker run -p 3306:3306 --name mysql-one -v /var/docker_data/mysql/data/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest

此时容器的3306端口会被映射到宿主机器的3306端口,这样我们就可以通过宿主机器的3306端口访问mysql了
查看docker是否启动:

# docker ps -a

在宿主机链接Mysql容器
使用PORTS显示的ip地址部分作为 -h 参数,如果不是在宿主机上,则使用宿主机的IP地址

# mysql -h 0.0.0.0 -u root -p

或者直接进入容器:

# docker exec -ti <容器id> /bin/bash

登录mysql

# mysql -uroot -p

输入刚设置的密码123456
成功进入mysql

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值