尊龙凯时人生就是博

ÔõÑùʹÓÃDockerÔÚLinuxÉÏʵÏÖÈÝÆ÷µÄ¿ìËÙǨáãºÍÔ¶³ÌÖÎÀí£¿

ÔõÑùʹÓÃdockerÔÚlinuxÉÏʵÏÖÈÝÆ÷µÄ¿ìËÙǨáãºÍÔ¶³ÌÖÎÀí£¿

¸ÅÊö

DockerÊÇÒ»ÖÖ³£ÓõÄÈÝÆ÷»¯ÊÖÒÕ£¬Äܹ»ÊµÏÖÓ¦ÓóÌÐòµÄ¿ìËÙ°²ÅźÍÖÎÀí¡£ÔÚLinuxÇéÐÎÏ£¬DockerµÄ×°ÖúÍʹÓÃÏà¶Ô¼òÆÓ£¬¿ÉÒÔͨ¹ýÏÂÁîÐлòÕß¿ÉÊÓ»¯¹¤¾ß¾ÙÐвÙ×÷¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDockerÔÚLinuxÉÏʵÏÖÈÝÆ÷µÄ¿ìËÙǨáãºÍÔ¶³ÌÖÎÀí£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

DockerµÄ×°ÖúÍÉèÖÃ

Ê×ÏÈ£¬ÐèÒªÔÚLinuxϵͳÉÏ×°ÖÃDocker¡£ÔÚ´ó´ó¶¼Linux¿¯Ðа汾ÖУ¬¿ÉÒÔͨ¹ýapt¡¢yum»òÕßdnfµÈ°ü¹ÜÀíÆ÷¾ÙÐÐ×°Öá£ÒÔÏÂÊÇÔÚUbuntuϵͳÉÏ×°ÖÃDockerµÄʾÀýÏÂÁ

$ sudo apt-get update
$ sudo apt-get install docker.io

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÑéÖ¤DockerÊÇ·ñÀÖ³É×°Öãº

$ docker version

µÇ¼ºó¸´ÖÆ

½Ó×Å£¬ÐèÒª½¨ÉèÒ»¸öÄܹ»Ô¶³Ì»á¼ûDockerµÄÓû§×é¡£¿ÉÒÔÊÖ¶¯½¨ÉèÒ»¸ö×飬Ȼºó½«±£´æµÄÓû§¼ÓÈë¸Ã×顣Ȼºó£¬ÐèÒªÖØеǼ²Å»ªÊ¹Óû§×éµÄ¸ü¸ÄÉúЧ£º

$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ newgrp docker

µÇ¼ºó¸´ÖÆ

×îºó£¬ÐèÒªÖØÆôDockerЧÀÍ£¬Ê¹ÆäÉúЧ£º

$ sudo systemctl restart docker

µÇ¼ºó¸´ÖÆ

ÈÝÆ÷µÄ¿ìËÙǨáã

DockerÈÝÆ÷µÄ¿ìËÙǨáãÊÇÖ¸½«ÈÝÆ÷´ÓÒ»¸öÖ÷»úÒƶ¯µ½ÁíÒ»¸öÖ÷»úµÄÀú³Ì¡£ÎªÁËʵÏÖÈÝÆ÷µÄ¿ìËÙǨá㣬ÐèÒªÏȽ«ÈÝÆ÷´ò°ü³ÉÒ»¸ö¾µÏñ£¬È»ºóÔÚеÄÖ÷»úÉÏÖØÐÂÔËÐоµÏñ¡£

Ê×ÏÈ£¬ÔÚÔ´Ö÷»úÉÏÉúÑÄÈÝÆ÷µÄÄ¿½ñ״̬Ϊ¾µÏñ£º

$ docker commit <container_id> <image_name>

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬ ÊÇÔ´Ö÷»úÉÏÕýÔÚÔËÐеÄÈÝÆ÷µÄ±êʶ·û£¬ ÊÇоµÏñµÄÃû³Æ¡£

È»ºó£¬½«¾µÏñµ¼³öµ½ÎļþÖУº

$ docker save <image_name> -o <output_file>

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬ ÊÇÒªµ¼³öµÄ¾µÏñµÄÃû³Æ£¬ Êǵ¼³öµÄÎļþµÄ·¾¶¡£

½Ó×Å£¬ÔÚÄ¿µÄÖ÷»úÉϵ¼Èë¾µÏñÎļþ£º

$ docker load -i <input_file>

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬ Êǵ¼ÈëµÄ¾µÏñÎļþµÄ·¾¶¡£

×îºó£¬ÔËÐе¼ÈëµÄ¾µÏñ£º

$ docker run -d <image_name>

µÇ¼ºó¸´ÖÆ

ÈÝÆ÷µÄÔ¶³ÌÖÎÀí

DockerÌṩÁËÔ¶³ÌAPI£¬¿ÉÒÔͨ¹ýHTTP RESTful½Ó¿ÚÀ´ÖÎÀíÈÝÆ÷ºÍ¾µÏñ¡£¿ÉÒÔʹÓÃcurlÏÂÁî»òÕß±àд½ÅÔ­À´ÊµÏÖ¶ÔDockerµÄÔ¶³ÌÖÎÀí¡£

Ê×ÏÈ£¬ÐèÒªÔÚDockerЧÀ͵ÄÉèÖÃÎļþÖÐÆôÓÃÔ¶³ÌAPI¡£±à¼­/lib/systemd/system/docker.serviceÎļþ£¬½«ExecStartÐиÄΪÈçÏÂÄÚÈÝ£º

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

µÇ¼ºó¸´ÖÆ

È»ºó£¬ÖØмÓÔغÍÖØÆôDockerЧÀÍ£º

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

µÇ¼ºó¸´ÖÆ

½Ó×Å£¬¿ÉÒÔʹÓÃcurlÏÂÁîÀ´·¢ËÍHTTPÇëÇó£¬ÊµÏÖ¶ÔDockerµÄÔ¶³ÌÖÎÀí¡£ÒÔÏÂÊÇһЩ³£ÓõÄcurlÏÂÁîʾÀý£º

»ñÈ¡DockerЧÀ͵İ汾ÐÅÏ¢£º

$ curl http://localhost:2375/version

µÇ¼ºó¸´ÖÆ

ÁгöËùÓÐÈÝÆ÷£º

$ curl http://localhost:2375/containers/json

µÇ¼ºó¸´ÖÆ

Æô¶¯Ò»¸öÈÝÆ÷£º

$ curl -X POST http://localhost:2375/containers/create?name=<container_name> -d '{"Image":"<image_name>"}'
$ curl -X POST http://localhost:2375/containers/<container_id>/start

µÇ¼ºó¸´ÖÆ

×èÖ¹Ò»¸öÈÝÆ÷£º

$ curl -X POST http://localhost:2375/containers/<container_id>/stop

µÇ¼ºó¸´ÖÆ

ɾ³ýÒ»¸öÈÝÆ÷£º

$ curl -X DELETE http://localhost:2375/containers/<container_id>

µÇ¼ºó¸´ÖÆ

³ýÁËcurlÏÂÁîÍ⣬»¹¿ÉÒÔʹÓñà³ÌÓïÑÔÀ´ÊµÏÖ¶ÔDockerµÄÔ¶³ÌÖÎÀí¡£ÒÔÏÂÊÇÒ»¸öʹÓÃPythonµÄʾÀý´úÂ룺

import requests

url = "http://localhost:2375/containers/json"
response = requests.get(url)
containers = response.json()
for container in containers:
    print(container["Names"][0])

µÇ¼ºó¸´ÖÆ

¸Ã´úÂë»áÁгöËùÓÐÈÝÆ÷µÄÃû³Æ¡£

×ܽá

ͨ¹ýDockerÔÚLinuxÉÏʵÏÖÈÝÆ÷µÄ¿ìËÙǨáãºÍÔ¶³ÌÖÎÀí¿ÉÒÔ¼«´óµØÀû±ã¿ª·¢ºÍÔËάְԱµÄÊÂÇé¡£Ö»Ðè¼òÆÓ¼¸¸ö°ì·¨£¬¼´¿ÉÇáËÉʵÏÖÈÝÆ÷µÄǨáãºÍÔ¶³ÌÖÎÀí¡£Ï£Íû±¾ÎÄÌṩµÄ´úÂëʾÀý¶ÔÄúÓÐ×ÊÖú£¬ÈôÊÇÓÐÈκÎÎÊÌâ»òÒÉÎÊ£¬ÇëËæʱ×Éѯ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃDockerÔÚLinuxÉÏʵÏÖÈÝÆ÷µÄ¿ìËÙǨáãºÍÔ¶³ÌÖÎÀí£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ