Docker, a long time will be together, a long time must be divided?

Source: Internet
Author: User
Tags sql error

As an operation or test, you can not understand the various kinds of open source tools released every day, but it is better to know about Docker, because this thing will change the micro and macro structure of software in the future. In the era of virtualization in the ascendant, and ushered in the Docker such a thing, continue to split the traditional software architecture, multi-process to play tired, play multi-container?

650) this.width=650; "src=" Http:// "title=" Docker . JPG "alt=" Wkiol1t0gvkyuukdaajrhe8do_0258.jpg "/>

Based on a few days of superficial testing, found a few interesting features:

1, isolation level of the problem. For application Container, you can see that the isolation level must be less than the virtual machine. However, although it appears that the 1th process of the Docker container is completely different from the host, it still has a connection to the host, such as launching an Apache in the Docker container and discovering that there are 3 Apache processes on the host, and that it is a completely different process number.

2, the issue of starting multiple services. Some people on the internet said that the service to be launched into a script, and then copy the script to the image, and then start with a cmd, I have not been successful trial. Finally, it's supervisord, and it's no problem trying to pull a lot of services. Note that there is no supervisord in the basic source of centos6.5, you must first install Epel

3, IP address problem. When running a Docker container, such as:

# docker run--name=mysql_contain1-h=mysql_host1-d-P docker_mysql

You can set the container name, you can set the container host name, but it seems to be unable to set the IP address?

Host has a DOCKER0 virtual network card, the address is, found the new Docker container IP address and then continue to accumulate.

4. If we have a MySQL image, is it possible to dynamically boot the container to get the load over, based on the host load threshold? Did a small experiment, when the host's MySQL connection number more than 500, start a MySQL container, the code is meaningless, purely testing:

# description:a demo to access MySQL based on dynamic Docker containers
# Python 2.7.6

Import MySQLdb
Import commands
Import OS
Import Random
Import time

Image_name= ' Docker_mysql '
master_host_ip= ' '
Prefix_cont= ' Mysql_cont '

Def getdockerip ():
I=random.randint (1,10000)
Shell= ' Mysqladmin-uroot-proot status|awk \ ' {print $4}\ '
thread = Int (commands.getoutput (shell))
Except Exception:
print ' Get thread number of Master SQL error '
Exit (1)
if (Thread > Num_thread):
str=prefix_cont+ '%d '%i
os.environ[' Cont_name ']=str
os.environ[' Image_name ']=image_name
Ret=os.system (' Docker run--name= ' $cont _name "-d-p $image _name >docker.log 2>&1 ')
if (ret <> 0):
print ' Create docker for MySQL error '
Exit (2)
Shell2= ' Docker inspect ' $cont _name "|grep ipaddress|grep-eo \ ' [0-9]{1,3}\. [0-9] {1,3}\. [0-9] {1,3}\. [0-9] {1,3}\ '
Str_ip=commands.getoutput (SHELL2)
Return STR_IP

def insertdata (v):
Des_host_ip=getdockerip ()
Print Des_host_ip
print ' begin to insert data to ' +DES_HOST_IP
Time.sleep (3)
My_conn=mysqldb.connect (Host=des_host_ip,port = 3306,user= ' root ', passwd= ' root ', db = ' db_test ')
cur = my_conn.cursor ()
Sql= "INSERT into T (ID) VALUES ('%d ')"% (v)
Cur.execute (SQL)
Cur.close ()
My_conn.commit ()
My_conn.close ()
print ' Insert data to ' +des_host_ip+ ' successfully! '
Except Mysqldb.error,e:
Print "Mysql Error%d:%s"% (E.args[0], e.args[1])
Exit (3)

InsertData (2015)


This article is from the "writing is a good habit" blog, please be sure to keep this source

Docker, a long time will be together, a long time must be divided?

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: 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.