MySQL tutorial and dockermysql tutorial in Docker

Source: Internet
Author: User
Tags mysql tutorial docker ps docker run

MySQL tutorial and dockermysql tutorial in Docker

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 ubuntuMAINTAINER erkan yanar <erkan.yanar@linsenraum.de> ENV DEBIAN_FRONTEND noninteractiveRUN apt-get install -y python-software-propertiesRUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943dbRUN add-apt-repository 'deb http://mirror2.hs-esslingen.de/mariadb/repo/10.0/ubuntu precise main'RUN apt-get updateRUN apt-get install -y mariadb-serverRUN echo "[mysqld]"      >/etc/mysql/conf.d/docker.cnfRUN echo "bind-address = 0.0.0.0"  >>/etc/mysql/conf.d/docker.cnfRUN echo "innodb_flush_method = O_DSYNC" >>/etc/mysql/conf.d/docker.cnfRUN echo "skip-name-resolve"    >>/etc/mysql/conf.d/docker.cnfRUN echo "init_file = /etc/mysql/init" >>/etc/mysql/conf.d/docker.cnfRUN echo "GRANT ALL ON *.* TO supa@'%' IDENTIFIED BY 'supa';" >/etc/mysql/init EXPOSE 3306USER mysqlENTRYPOINT 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.446suser 0m0.264ssys  0m0.211s

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 -2CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS     NAMES6d3a5181cd56  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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.