In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Detailed explanation of installation and configuration of docker python api
1.docker host configuration file modification
$vim / etc/default/docker # add DOCKER_OPTS= "- H tcp://0.0.0.0:2375-H unix://var/run/docker.sock" to the existing OPTS so that you can connect to the docker daemon through port 2375 of tcp, and the second-H and later contents can be omitted
two。 Install docker-py
$sudo pip install docker-py
3. Write api scripts
Reference documentation
Http://docker-py.readthedocs.org/en/latest/
From docker import Clientd=Client (base_url='tcp://10.109.252.221:2375',version='auto',timeout=10) # Note to fill in the url port version number and timeout def containerCreate (* * command): container=d.create_containter (* * command) print container#. Here the non-keyword variable length parameter * * command is used, and the parameters you need can be transmitted in dictionary form. And the function will automatically identify the parameter containerCreate in the dictionary (* * {'name':' test1', 'command':' / bin/bash','image':'ubuntu'}) # here, please use * * double asterisk to pass the argument, otherwise an error will occur.
4. Port binding, disk mount, and link operation
Def containerCreate (port, volume, link, * * command): # create container command ['host_config'] = d.create_host_config (port_bindings=port, binds= [volume], links=link) container= d.create_container (* * command) d.start (container=container.get (' Id')) print containercontainerCreate (* * {'name':' test1','stdin_open':True,'tty':True) 'command':' / bin/bash', 'image':' 10.109.252.221 ports': 5000 pictups, 'ports': [8008],' port': {8008 ports': 9995}, 'volume':'/home/ubuntu/test:/test','link': {' mysql':'db'}}) # of which Ports must declare that port and volume are written by myself and are used to pass the parameter # ports declares the open port of the container. In port, the first is the container port, and the second is the host port, which is the opposite of dokcer run-p. # link operation requires passing dictionaries or tuples. If I have failed to use tuples, I can use a dictionary.
If you have any questions, please leave a message or go to the community to exchange and discuss, thank you for reading, hope to help you, thank you for your support!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.