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 ../
# 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"]
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 ....