Reading: docker container and container cloud (2); reading docker

Source: Internet
Author: User
Tags download redis docker ps docker run haproxy install redis

Reading: docker container and container cloud (2); reading docker

Summarize the learning and building process of docker
I read the 3.1 kernel, which is quite awesome.
After reading the plug-ins on the internet, I tried them based on python and simulators. They were all done. As a result, the ones on the simulator could not be opened...

1. Obtain the image docker pull haproxydocker pull redisdocker pull django2 and start three redis instances in Six containers (one master, two slave) docker run-it -- name redis-master redis/bin/bashdocker run-it-name redis-slave1 -- link redis-master: master redis/bin/bashdocker run-it -- name redis-slave2 -- link redis-master: master redis/bin/bash two Djangodocker run-it -- name APP1 -- link redis-master: db-v/root/Projects/Django/App1:/usr/src/app django/bin/B Ashdocker run-it -- name APP2 -- link redis-master: db-v/root/Projects/Django/App2: /usr/src/app django/bin/bash a HAProxydocker run-it -- name HAProxy -- link APP1: APP1 -- link APP2: APP2-p 6301: 6301-v ~ /Projects/HAProxy:/tmp haproxy/bin/bash seven windows are recommended.
2. Configure the three redis containers that do not use the-v parameter to view their default mount points. view the corresponding mount point docker inspect imageID | grep Source to download redis from the Internet. conf [Address: http://download.redis.io/releases/redis-4.0.6.tar.gz.pdf file. The corresponding major version is as follows:

1. Use docker ps-a to view all the containers. Run the docker inspect f2b | grep-E "Source | Destination" command to view the Mount directories of the three redis instances.
Source corresponds to the mount point of the host, and Destination corresponds to mount point 2 in the container, copying redis. confcd <Source. value> cp <you_redis.conf_dir>/redis. conf redis, conf3, modify parameters, and the master node modifies the three parameters band 0.0.0.0 # Otherwise, the master redisdeamonize yespidfile/var/run/redis cannot be found. pid from the node to modify the four parameters band 0.0.0.0deamonize yespidfile/var/run/redis. pid # Here this should not all be done slaveof master 63794, enter the corresponding container 5, enter the corresponding mount point directory, cd <Destination. value> 6. Set the value to redis. copy conf to/usr/local/bin/, 7, start redis, redis. server redis. conf8: test the command to access redis from the master-slave redisredis-cli, and set the value and value using set and get.

3. Configure two apps
1. Run the pip command in the container to install redispip install redis for testing.
2, create and start the App to use the python + Django environment in the container to generate cd/usr/src/appmkdir dockerwebcd dockerwebdjango-admin.py startproject rediswebcd rediswebpython manage. py startapp helloworld generates the helloworld file and switches it to the host. Edit the corresponding configuration files: views, setting, urlscd/root/Projects/Django/App1/dockerweb/redisweb/helloworld/vim views. pyfrom django. shortcuts import render # Create your views here. from django. http import HttpResponseimport redisdef hello (request): str = redis. _ file _ str + = "<br>" r = redis. redis (host = 'db', port = 6379, db = 0) info = r.info () str + = ("set hi <br>") r. set ('hi', 'helloworld-app1') str + = ("Get Hi: % s <br>" % r. get ('Hi') str + = ("Redis Info: <br>") str + = ("Key: Info Value") for key in info: str + = ("% s: % s <br>" % (key, info [key]) return HttpResponse (str) EDIT setting file cd .. /redisweb/# allow external access ALLOWED_HOSTS = ['*'] # Add a helloworld Project # Application definitionINSTALLED_APPS = ['django. contrib. admin', 'django. contrib. auth ', 'django. contrib. contenttypes ', 'django. contrib. sessions ', 'django. contrib. messages ', 'django. contrib. staticfiles ', 'helloworld',] edit urls. py add reference from helloworld. views import hello add url (R' ^ helloworld $ ', hello ),

Compile the helloworld project python manage. py makemigrationspython manage. py migratepython manage. py createsuperuser # Set the username and password for backend management.
Start the helloworld project python manage. py runserver 0.0.0.0: 8001

4. Configure HAProxy container nodes
1. Edit the haproxy. cfg file cd ~ /Projects/HAProxyvim haproxy. export global log 127.0.0.1 local0 maxconn 4096 chroot/usr/local/sbin daemon nbproc 4 pidfile/usr/local/sbin/haproxy. piddefaults log 127.0.0.1 local3 mode http option dontlognull option redispatch retries 2 maxconn 2000 balance roundrobin timeout connect 5000 ms timeout client 50000 ms timeout server 50000 mslisten redis_proxy bind 0.0.0.0: 6301 bind-process 2 # pao zai laing ge CPU shang 'stats enable stats uri/haproxy-stats server APP1 APP1: 8001 check inter 2000 rise 2 fall 5 server APP2 APP2: 8002 check inter 2000 rise 2 fall 5
Note: bind 0.0.0.0: 6301, bind-process 2 # pao zai laing ge CPU shang is missing ')
2. Enter the container and start cd/tmpcp haproxy. cfg/usr/local/sbincd/usr/local/sbinhaproxy-f haproxy. cfg Note: killall HAProxy test: killall haproxy


A wonderful day to cheer up tomorrow
Copyright Disclaimer: cainiao course, please advise! Http://blog.csdn.net/u013991917/article/details/79039635

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.