Regarding virtualization I am a LXC guy. Nevertheless Docker has won a lot of attention and I would like to show how to use MySQL with Docker.
What is Docker?
In fact Docker is a wrapper around LXC. It is fun to use. Docker has the philosophy to virtualize single applications using LXC. So in our example we are going to start a mysqld in a chroot environment encapsulated in his own Namespaces. (You can even set Cgroups resources.) One of the main points regarding Docker is the usage of a union filesystem (aufs). So when you start a Docker Container it gets his aufs mount and only changed data is written down.
Aufs is great for a lot of applications and sufficient for Database testing. I just want to share a simple - more educational, than effective - Dockerfile. Dockerfiles are the buildscripts for the Docker images.
Lets have a look at the 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]" >/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 ON *.* TO supa@'%' IDENTIFIED BY 'supa';" >/etc/mysql/init EXPOSE 3306 USER mysql ENTRYPOINT mysqld
You should change it the way you like. If you understand it, go on and optimize it. I.e. reduce the run stages:)
Lets quick build our image (named mysql)
> cat $DOCKERFILENAME | docker build -t mysql -
Great! Let's for fun start 51 Containers:
> 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
All on my laptop. Think about the performance using KVM :)
> docker ps | grep mysqld |wc -l 51 > 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
Have fun \o/
Erkan
PlanetMySQL Voting: Vote UP / Vote DOWN
No comments:
Post a Comment