DockerºÍLinux£ºÔõÑùÓÅ»¯ÈÝÆ÷µÄÐÔÄÜ£¿
dockerºÍlinux£ºÔõÑùÓÅ»¯ÈÝÆ÷µÄÐÔÄÜ£¿
СÐò£º
Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄѸÃÍÉú³¤£¬ÔõÑùÓÅ»¯ÈÝÆ÷µÄÐÔÄÜÒѳÉΪÈÝÆ÷ʹÓÃÕߺÍÔËάְԱ¹Ø×¢µÄ½¹µã¡£±¾ÎĽ«ÏÈÈÝһЩÓÅ»¯ÈÝÆ÷ÐÔÄܵļ¼ÇɺÍÕ½ÂÔ£¬Öصã¹Ø×¢ÔÚʹÓÃDockerÈÝÆ÷ʱÔõÑùʹÓÃLinuxÌṩµÄ¹¦Ð§À´ÓÅ»¯ÈÝÆ÷µÄÐÔÄÜ¡£
Ò»¡¢Ê¹ÓÃÊʵ±µÄ»ù´¡¾µÏñ
»ù´¡¾µÏñÊÇÈÝÆ÷µÄÆðµã£¬Ëü¾öÒéÁËÈÝÆ÷µÄÇéÐκÍһЩ»ù´¡×é¼þµÄ°æ±¾¡£Ñ¡ÔñÒ»¸öºÏÊʵĻù´¡¾µÏñºÜÊÇÖ÷Òª¡£Ò»Ñùƽ³£À´Ëµ£¬¹Ù·½Î¬»¤µÄ»ù´¡¾µÏñ»á½ÏÁ¿Îȹ̺ÍÇå¾²¡£±ðµÄ£¬Ö»¹ÜÑ¡Ôñ½ÏСµÄ»ù´¡¾µÏñ£¬×èÖ¹ÈßÓàµÄ×é¼þºÍÈí¼þ°üµÄ×°Öá£Ò»¸ö½ÏСµÄ»ù´¡¾µÏñ»áïÔÌÈÝÆ÷µÄÆô¶¯Ê±¼äºÍÕ¼ÓõĴÅÅ̿ռ䣬´Ó¶øÌá¸ßÈÝÆ÷µÄÐÔÄÜ¡£ÏÂÃæÊÇÒ»¸öʹÓùٷ½ÌṩµÄAlpine Linux×÷Ϊ»ù´¡¾µÏñµÄʾÀý£º
FROM alpine:latest
µÇ¼ºó¸´ÖÆ
¶þ¡¢ÓÅ»¯×ÊÔ´ÏÞÖÆ
ÔÚÔËÐÐÈÝÆ÷ʱ£¬¿ÉÒÔͨ¹ýÉèÖÃ×ÊÔ´ÏÞÖÆÀ´¿ØÖÆÈÝÆ÷ʹÓõÄ×ÊÔ´¡£×ÊÔ´ÏÞÖÆ¿ÉÒÔ×èÖ¹ÈÝÆ÷Ì«¹ýʹÓÃCPU¡¢ÄÚ´æºÍ´ÅÅ̵È×ÊÔ´£¬²¢Ìá¸ßÈÝÆ÷ÐÔÄܺÍÎȹÌÐÔ¡£¿ÉÒÔʹÓÃDockerÌṩµÄ–cpusºÍ–memory²ÎÊýÀ´ÏÞÖÆÈÝÆ÷ʹÓõÄCPU½¹µãÊýºÍÄÚ´æ¾Þϸ¡£ÏÂÃæÊÇÒ»¸öÉèÖÃ×ÊÔ´ÏÞÖƵÄʾÀý£º
docker run --cpus=1 --memory=1g my_container
µÇ¼ºó¸´ÖÆ
Èý¡¢ÉèÖúÏÀíµÄÈÝÆ÷µÄÍøÂçÉèÖÃ
ÍøÂçÉèÖÃÊÇÈÝÆ÷ÐÔÄÜÓÅ»¯µÄÁíÒ»¸öÖ÷Òª·½Ãæ¡£ÔõÑùÉèÖÃÈÝÆ÷µÄÍøÂçÉèÖÃÈ¡¾öÓÚÏÖʵµÄÐèÇóºÍ³¡¾°¡£Ò»Ñùƽ³£À´Ëµ£¬¿ÉÒÔͨ¹ýÒÔϼ¸ÖÖ·½·¨À´ÓÅ»¯ÈÝÆ÷µÄÍøÂçÐÔÄÜ£º
ʹÓÖnetwork²ÎÊýÖ¸¶¨ÈÝÆ÷ʹÓõÄÍøÂçÀàÐÍ¡£¹ØÓÚÐèÒª¸ßÐÔÄܵÄÈÝÆ÷£¬¿ÉÒÔÑ¡ÔñʹÓÃhostÍøÂçģʽ£¬Ê¹µÃÈÝÆ÷ºÍËÞÖ÷»ú¹²ÏíÍøÂçÃüÃû¿Õ¼ä£¬ïÔÌÍøÂçת·¢µÄ¿ªÏú¡£
×èֹʹÓÃÈÝÆ÷ÄÚµÄDNSÆÊÎö¡£¿ÉÒÔͨ¹ýÔÚÈÝÆ÷ÄÚ²¿µÄ/etc/hostsÎļþÖÐÊÖ¶¯ÉèÖÃIPµØµãºÍÓòÃûµÄÓ³Éä¹Øϵ£¬×èÖ¹ÈÝÆ÷ÄÚµÄDNSÆÊÎö£¬Ìá¸ßÍøÂç»á¼ûµÄËÙÂÊ¡£
×èֹʹÓÃbridgeÍøÂçģʽ¡£ÔÚĬÈÏÇéÐÎÏ£¬DockerʹÓÃbridgeÍøÂçģʽ£¬ÕâÖÖģʽÏÂÈÝÆ÷Ö®¼äÐèҪͨ¹ýNATת·¢À´¾ÙÐÐͨѶ£¬»á±¬·¢ÌØÁíÍ⿪Ïú¡£¿ÉÒÔ˼Á¿Ê¹ÓÃÈÝÆ÷µÄhostÍøÂçģʽ»òÕß×Ô½ç˵ÍøÂçÀ´×èÖ¹Õâ¸öÎÊÌâ¡£
ËÄ¡¢Ê¹ÓÃÊý¾Ý¾íºÍ¹²ÏíÄÚ´æ
Êý¾Ý¾íÊǽ«ËÞÖ÷»úÉϵÄÎļþ»òĿ¼¹ÒÔص½ÈÝÆ÷ÄÚ²¿£¬¿ÉÒÔʵÏÖÊý¾ÝµÄ¹²ÏíºÍ³¤ÆÚ»¯¡£Ê¹ÓÃÊý¾Ý¾í¿ÉÒÔ×èÖ¹ÈÝÆ÷ÄÚµÄÊý¾Ýɥʧ£¬²¢Ìá¸ßÈÝÆ÷¶Ô³¤ÆÚ»¯Êý¾ÝµÄ¶ÁдÐÔÄÜ¡£ÁíÍ⣬Docker»¹ÌṩÁ˹²ÏíÄÚ´æµÄ¹¦Ð§£¬¿ÉÒÔÈöà¸öÈÝÆ÷Ö®¼ä¹²ÏíÄÚ´æ¶Î£¬Ìá¸ßÈÝÆ÷¼äͨѶµÄÐÔÄÜ¡£
ÏÂÃæÊÇÒ»¸öʹÓÃÊý¾Ý¾íµÄʾÀý£º
docker run -v /host/data:/container/data my_container
µÇ¼ºó¸´ÖÆ
Îå¡¢ºÏÀíʹÓûº´æ
ºÏÀíʹÓûº´æ¿ÉÒÔÌá¸ßÈÝÆ÷µÄ¹¹½¨ËÙÂʺÍÔËÐÐÐÔÄÜ¡£Ê×ÏÈ£¬¿ÉÒÔʹÓÃDockerµÄ¹¹½¨»º´æ»úÖÆ£¬×èÖ¹Öظ´µÄ¹¹½¨²Ù×÷¡£Æä´Î£¬¿ÉÒÔÔÚÈÝÆ÷ÄÚʹÓûº´æÀ´Ìá¸ßÎļþ¶ÁдµÄÐÔÄÜ¡£ÏÂÃæÊÇÒ»¸öÔÚDockerfileÖÐʹÓûº´æµÄʾÀý£º
FROM alpine:latest COPY . /app RUN apk add --no-cache --virtual .build-deps gcc libc-dev && cd /app && make && apk del .build-deps && rm -rf /var/cache/apk/*
µÇ¼ºó¸´ÖÆ
½áÂÛ£º
ͨ¹ýºÏÀíʹÓûù´¡¾µÏñ¡¢ÓÅ»¯×ÊÔ´ÏÞÖÆ¡¢ÉèÖúÏÀíµÄÍøÂçÉèÖá¢Ê¹ÓÃÊý¾Ý¾íºÍ¹²ÏíÄÚ´æ¡¢ºÏÀíʹÓûº´æµÈÒªÁ죬¿ÉÒÔÓÐÓÃÌá¸ßÈÝÆ÷µÄÐÔÄÜ¡£ÖµµÃ×¢ÖصÄÊÇ£¬²î±ðµÄ³¡¾°¿ÉÄÜÐèÒª²î±ðµÄÓÅ»¯Õ½ÂÔ£¬Ê¹ÓÃÕßÐèҪƾ֤×Ô¼ºµÄÏÖʵÐèÇóÑ¡ÔñºÏÊʵÄÒªÁìÀ´ÓÅ»¯ÈÝÆ÷µÄÐÔÄÜ¡£
²Î¿¼×ÊÁÏ£º
https://docs.docker.com/config/containers/resource_constraints/
https://docs.docker.com/network/
https://docs.docker.com/storage/
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
ÒÔÉϾÍÊÇDockerºÍLinux£ºÔõÑùÓÅ»¯ÈÝÆ÷µÄÐÔÄÜ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡