文章目录
  1. 1. Use Docker for MySQL deployment
  2. 2. OS environment
    1. 2.1. Run software updates:
    2. 2.2. install EPEL repository
    3. 2.3. Install Docker Tools
    4. 2.4. Start Docker as service
    5. 2.5. Configure Docker to start on startup
    6. 2.6. check docker service
    7. 2.7. install Docker done
  3. 3. Make a docker images
    1. 3.1. frist download percona mysql rpms
    2. 3.2. make a docker file
    3. 3.3. build the image
    4. 3.4. push image
  4. 4. use exsiting image
    1. 4.1. download image
    2. 4.2. run container after download
      1. 4.2.1. run like shell
      2. 4.2.2. run like a tool
    3. 4.3. get container ip :
    4. 4.4. make image use container
  5. 5. Summary

Use Docker for MySQL deployment

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud
see the details :https://www.docker.com/whatisdocker/

OS environment

CentOs 6.6 newest version

Run software updates:

sudo -s
yum update -y
yum install -y wget git

install EPEL repository

Enable EPEL repository so you can install some extra packages:

1
2
3
cd /tmp
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm

Install Docker Tools

sudo yum -y install docker-io

Start Docker as service

sudo service docker start

Configure Docker to start on startup

sudo chkconfig docker on

check docker service

service docker status 
docker info 
docker images 
docker ps 

install Docker done

Now the docker enviorement is ready 

Make a docker images

you can download my images build for percona server at next section

frist download percona mysql rpms

1
2
3
4
mkdir /data/docker/repos -p 
cd /data/docker/repos
wget http://www.percona.com/downloads/Percona-Server-5.6/Percona-Server-5.6.21-70.0/binary/redhat/6/x86_64/Percona-Server-5.6.21-70.0-r688-el6-x86_64-bundle.tar
cd ../

make a docker file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# MySQL 
# use centos base image
FROM centos:centos6
# specify the maintainer
MAINTAINER ruiayliln "ruiaylin@gmail.com"
# update get mysql tars repos
RUN yum install -y wget tar
RUN yum install -y perl-libs perl perl-DBD-MySQL perl-DBI perl-Module-Pluggable perl-Pod-Escapes perl-Pod-Simple perl-Time-HiRes perl-IO-Socket-SSL
RUN yum install -y libaio screen
RUN yum install -y python-setuptools
# scp file
ADD repos/Percona-Server-5.6.21-70.0-r688-el6-x86_64-bundle.tar /tmp/
# install some dependencies
RUN ls -al /tmp/
# install
RUN rpm -ivh /tmp/Percona-Server-shared-56-5.6.21-rel70.0.el6.x86_64.rpm
RUN rpm -ivh /tmp/Percona-Server-devel-56-5.6.21-rel70.0.el6.x86_64.rpm
RUN rpm -ivh /tmp/Percona-Server-56-debuginfo-5.6.21-rel70.0.el6.x86_64.rpm
RUN rpm -ivh /tmp/Percona-Server-client-56-5.6.21-rel70.0.el6.x86_64.rpm
#configure /etc/file
ADD my.cnf /etc/
RUN rpm -ivh /tmp/Percona-Server-server-56-5.6.21-rel70.0.el6.x86_64.
# check mysql version
RUN mysql -V
RUN mysqld -V
# python-setuptools
RUN /usr/sbin/mysqld & \
sleep 10s &&\
echo " grant all privileges on *.* to admin@'localhost' identified by 'studytest' with grant option;grant all privileges on *.* to admin@'127.0.0.1' identified by 'studytest' with grant option;grant all privileges on *.* to opsdba@'%' identified by 'studytest' ;grant REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'replication'@'%' IDENTIFIED BY 'studytest';grant SELECT,CREATE,DROP,PROCESS,FILE,INDEX,ALTER,SUPER,LOCK TABLES ON *.* TO 'mtain'@'%' IDENTIFIED BY 'studytest'; flush privileges;" | mysql
# expose mysqld port
EXPOSE 3306

CMD ["/usr/bin/mysqld_safe"]

build the image

1
docker build -t ruiaylin/percona56-gtid-sid1  .

push image

register : https://index.docker.io/account/signup/
input username && password when you push image

push:

1
2
docker push ruiaylin/percona56-gtid-sid1:v1
docker push ruiaylin/percona56-gtid-sid2:v1

check :

1
2
3
4
[root@mytestdb01 ~]# docker search ruiaylin/percona56-gtid-sid 
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ruiaylin/percona56-gtid-sid1 percona5.6s1 1
ruiaylin/percona56-gtid-sid2 percona5.6 1

use exsiting image

download percona mysql server for our envirament

download image

1
2
3
4
docker search ruiaylin/percona56-gtid-sid
#download
docker pull ruiaylin/percona56-gtid-sid2:v1
docker pull ruiaylin/percona56-gtid-sid1:v1

run container after download

1
2
3
4
5
docker images 
[root@mytestdb01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ruiaylin/percona56-gtid-sid2 v1 44754483adfa Less than a second ago 1.463 GB
ruiaylin/percona56-gtid-sid1 v1 78eaac9dbe1e Less than a second ago 1.484 GB

run like shell

command :

1
docker run -it ruiaylin/percona56-gtid-sid1:v1  /bin/bash

like :

1
2
3
4
5
6
7
8
[root@mytestdb01 ~]# docker run -it ruiaylin/percona56-gtid-sid1:v1  /bin/bash
[root@9ed2b3dc0f5f /]#
[root@9ed2b3dc0f5f /]#
[root@9ed2b3dc0f5f /]#
[root@9ed2b3dc0f5f /]# mysqld_safe &
[1] 14
[root@9ed2b3dc0f5f /]# 141223 02:17:47 mysqld_safe Logging to '/data/mysql3306/log/alert.log'.
141223 02:17:47 mysqld_safe Starting mysqld daemon with databases from /data/mysql3306/data

if you execute exit command , the container is stop , if you want keep the container running , use Ctrl + p ; Ctrl + q to exit the termail .
you can start Several container , use the same command , one ip per container .

run like a tool

command :

1
docker run -it ruiaylin/percona56-gtid-sid1:v1  /usr/bin/mysqld_safe

log like this :

1
2
3
4
[root@mytestdb01 ~]# docker run -it ruiaylin/percona56-gtid-sid1:v1  /usr/bin/mysqld_safe 
141223 02:27:27 mysqld_safe Logging to '/data/mysql3306/log/alert.log'.
141223 02:27:27 mysqld_safe Starting mysqld daemon with databases from /data/mysql3306/data
[root@mytestdb01 ~]#

use “Ctrl + p ; Ctrl + q” to exit the terminal

get container ip :

use docker inspect command to get the env :

1
2
3
4
[root@mytestdb01 ~]# for x in  ' docker ps | grep -v CONTAINER | awk  '{print $1}'   '; do   ip='docker inspect -f '{{ .NetworkSettings.IPAddress }}' $x ';echo $x:$ip  ; done
ecb06307f126:172.17.0.7
74dc6520fb70:172.17.0.6
9ed2b3dc0f5f:172.17.0.5

“ ‘ “ should change to “ ` “, when you execute the command above .

make image use container

1
docker commit -a "ruiaylin  <ruiaylin@gmail.com >"  0087e76555d2  ruiaylin/percona56-gtid-sid1:v2

Summary

now , you mysql environment for study or testing is done , enjoy it buddy ....
文章目录
  1. 1. Use Docker for MySQL deployment
  2. 2. OS environment
    1. 2.1. Run software updates:
    2. 2.2. install EPEL repository
    3. 2.3. Install Docker Tools
    4. 2.4. Start Docker as service
    5. 2.5. Configure Docker to start on startup
    6. 2.6. check docker service
    7. 2.7. install Docker done
  3. 3. Make a docker images
    1. 3.1. frist download percona mysql rpms
    2. 3.2. make a docker file
    3. 3.3. build the image
    4. 3.4. push image
  4. 4. use exsiting image
    1. 4.1. download image
    2. 4.2. run container after download
      1. 4.2.1. run like shell
      2. 4.2.2. run like a tool
    3. 4.3. get container ip :
    4. 4.4. make image use container
  5. 5. Summary