Speaking of virtualization technology, I love linuxiner iner (LXC. But with the increasing popularity of Docker technology, I want to show you how to use MySQL with Docker.
What is Docker?
In fact, Docker is the LXC encapsulation. It is very interesting to use. Docker uses LXC to virtualize each application. In the following example, we will start a mysql instance encapsulated in the namespace of the chroot environment (you can also set the resources of Cgroups) one of the highlights of using Docker is the Unified File System (aufs ). Therefore, when a Docker container is started, it records the total number of aufs and only updates the newly written data.
Aufs is very useful for most applications and can well support database testing. Here I just want to make a simple example-it may not be highly practical-Dockerfile. Dockerfile is the build script of the Docker image.
Let's take a look at the Dockerfile content:
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 can change it as needed. After understanding the general idea, you can further optimize the code. For example, there are few running steps :)
Run the command (named mysql)
> Cat $ DOCKERFILENAME | docker build-t mysql-
Good! Start 51 containers:
> Time for I in $ (seq 10 60); do docker run-d-p 50 $ I: 3306 mysql; done
..
Real 0m27. 446 s
User 0m0. 264 s
Sys 0m0. 211 s
This is all the results in my laptop. It will be better if KVM is used :)
> 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
Come and try \ o/
Docker details: click here
Docker: click here
New virtualization options for the open-source project Docker and Red Hat
Dockerlite: lightweight Linux Virtualization
Detailed explanation of the entire process of building Gitlab CI for Docker
What is the difference between Docker and a normal Virtual Machine?
Docker will change everything