Referring to virtualization, I'm a Linuxcontainer (LXC) lover. But as Docker technology has gained prominence, I want to show you how to use MySQL with Docker
What is Docker?
In fact, Docker is the LXC package. It's fun to use. Docker uses LXC to virtualize each application. So in the next example, we start a chroot environment in which a MySQL instance is encapsulated in its own namespace (you can also set cgroups corresponding resources) One of the highlights of using Docker is the Unified file System (AUFS). So when a Docker container is started, it records the total number of its aufs and updates only the newly written data.
Aufs is useful for most applications and can also be a good support for database testing. I just want to make a simple example of this-just a dockerfile, practicality may not be high. Dockerfile is a build script for Docker mirroring
Let's look at the contents of Dockerfile:
From Ubuntu
maintainer Erkan yanar <erkan.yanar@linsenraum.de>
ENV debian_frontend noninteractive
Run Apt-get install-y python-software-properties
run Apt-key adv--recv-keys--keyserver hkp:// keyserver.ubuntu.com:80 0xcbcb082a1bb943db
RUN add-apt-repository ' Deb http://mirror2.hs-esslingen.de/mariadb/ Repo/10.0/ubuntu Precise main '
run Apt-get update
run apt-get install-y mariadb-server
run echo ' [mysqld] ' C9/>>/ETC/MYSQL/CONF.D/DOCKER.CNF
RUN echo "bind-address = 0.0.0.0" >>/etc/mysql/conf.d/ DOCKER.CNF
run echo "Innodb_flush_method = O_dsync" >>/etc/mysql/conf.d/docker.cnf
run Echo " Skip-name-resolve " >>/etc/mysql/conf.d/docker.cnf
RUN echo" init_file =/etc/mysql/init ">>/ ETC/MYSQL/CONF.D/DOCKER.CNF
RUN echo "GRANT all" *.* to supa@ '% ' identified by ' Supa '; ">/etc/mysql/init
E Xpose 3306
USER mysql
entrypoint mysqld
You can change it according to your own needs. After you understand the effect, you can further optimize the code. For example, less running steps:)
Run a look (named MySQL)
> Cat $DOCKERFILENAME | Docker build-t MySQL-
Very good! Start 51 containers to see:
> Time for I in $ (seq 10 60); Do Docker run-d-P 50$i:3306 MySQL; Done
..
Real 0m27.446s
user 0m0.264s
sys 0m0.211s
This is the result of my notebook. It would be better if you use KVM performance:)
> Docker PS | grep mysqld |wc-l
> Docker ps | head-2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d3a5181cd56 mysql:latest /bin/sh-c mysqld about a minute ago up about a Minute 0.0.0.0:5060->3306/tcp Lonely_pare
Come on, give it a try, \o/.