{"id":7724,"date":"2018-10-03T07:26:16","date_gmt":"2018-10-02T23:26:16","guid":{"rendered":"http:\/\/rmohan.com\/?p=7724"},"modified":"2018-10-03T07:30:36","modified_gmt":"2018-10-02T23:30:36","slug":"docker-centos","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7724","title":{"rendered":"docker centos"},"content":{"rendered":"<p>[root@ docker]# cat \/etc\/yum.repos.d\/docker-main.repo<br \/>\n[docker-main-repo]<br \/>\nname=Docker main Repository<br \/>\nbaseurl=https:\/\/get.daocloud.io\/docker\/yum-repo\/main\/CentOS\/7<br \/>\nenabled=1<br \/>\ngpgcheck=1<br \/>\ngpgkey=https:\/\/get.daocloud.io\/docker\/yum\/gpg<\/p>\n<p>[root@ docker]# yum install docker-engine \u2013y<\/p>\n<p>[root@ docker]# docker &#8211;version<br \/>\nDocker version 17.05.0-ce, build 89658be<\/p>\n<p>firewall-cmd &#8211;add-port=2377\/tcp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=7946\/tcp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=7946\/udp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=4789\/udp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;reload**<\/p>\n<p>[root@ docker]# cat \/etc\/docker\/daemon.json<br \/>\n{<br \/>\n&#8220;insecure-registries&#8221;:[&#8220;docker-registry.rmohan.com:5000&#8221;],<br \/>\n&#8220;log-driver&#8221;:&#8221;json-file&#8221;,<br \/>\n&#8220;log-opts&#8221;:{&#8220;max-size&#8221;:&#8221;1024m&#8221;,&#8221;max-file&#8221;:&#8221;2&#8243;}<br \/>\n}<\/p>\n<p>[root@ ~]# systemctl restart docker.service<\/p>\n<p>[root@master ~]# docker swarm join-token worker<br \/>\nTo add a worker to this swarm, run the following command:<\/p>\n<p>docker swarm join \\<br \/>\n&#8211;token SWMTKN-1-4p4djbee1kqcss8x5prfzg6v01x0y7hfa7rqob6rffg6e2p2wq-278qafb9ptpqtfebr0kyngi0b \\<br \/>\n192.168.191.6:2377<\/p>\n<p>[root@filters ~]# docker node ls<br \/>\nID HOSTNAME STATUS AVAILABILITY MANAGER STATUS<br \/>\n0y4ga216x49nd9zt821afe45p * mohan_191_6 Ready Active Reachable<br \/>\n56mgklq3iyf0ajioytmtr0b44 mohan_191_10 Ready Active<br \/>\nb5mljua4e0tchrrk871ggbw7r mohan_191_7 Ready Active Reachable<br \/>\ngxm1gvh8lx2eja36a4cms9w98 mohan_182_212 Ready Active<br \/>\nhgweoxc5vmy9g30uyozmbumhj mohan_182_213 Ready Active<br \/>\nlluom23ugtfuiwphcye2frbmd mohan_182_215 Ready Active<br \/>\nom0ezdbqzdvavn8z8d844osbo mohan_182_214 Ready Active<br \/>\nt00tu1qs7wbll2fg2accsx7wf mohan_191_4 Ready Active Leader<br \/>\ntk89xphvsg16rz7b7l6lam4xv mohan_191_9 Ready Active<br \/>\nxbcx4hx2lq3ji8zog2ayzctat mohan_191_8 Ready Active Reachable<br \/>\ny3pnrw9jt69vkfiuxrs0co7ke mohan_191_5 Ready Active Reachable<\/p>\n<p>docker swarm join &#8211;token manger node ip:port<\/p>\n<p>[root@dockernode~]#docker swarm join &#8211;token SWMTKN-1-4p4djbee1kqcss8x5prfzg6v01x0y7hfa7rqob6rffg6e2p2wq-278qafb9ptpqtfebr0kyngi0b 192.168.191.6:2377<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>$ docker run Ubuntu:14.04 \/bin\/echo &#8216;Hello world&#8217;<br \/>\nHello world<\/p>\n<p>$ docker run -t -i ubuntu:14.04 \/bin\/bash<br \/>\nroot@af8bae53bdd3:\/#<\/p>\n<p>$ docker run -d ubuntu \/bin\/sh -c &#8220;while true; do echo hello world; sleep 1; done&#8221;<br \/>\ncb30b87566d0550ec5f1232d148c5ffed6546c347889e58a6405579f2af73f2a<\/p>\n<p>$ docker container ls<br \/>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br \/>\ncb30b87566d0 ubuntu &#8220;\/bin\/sh -c &#8216;while t\u2026&#8221; 2 minutes ago Up 2 minutes goofy_mcclintock<\/p>\n<p>$ docker container logs goofy_mcclintock<br \/>\nhello world<br \/>\nhello world<br \/>\nhello world<\/p>\n<p>$ docker container stop goofy_mcclintock<br \/>\ngoofy_mcclintock<\/p>\n<p>$ docker container ls -a<br \/>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br \/>\ncb30b87566d0 ubuntu &#8220;\/bin\/sh -c &#8216;while t\u2026&#8221; 20 minutes ago Exited (137) 23 seconds ago goofy_mcclintock<\/p>\n<p>$ docker attach e1ff<br \/>\nroot@e1ffd4f792fe:\/#<\/p>\n<p>Note: If exit from this stdin, it will cause the container to stop.<\/p>\n<p>The exec command<br \/>\n-i -t parameter<br \/>\ndocker exec can be followed by multiple parameters, here mainly the -i -t parameter.<br \/>\nWhen only the -i parameter, since there is no allocation of pseudo-terminals, the interface is not familiar Linux command prompt, the command execution<br \/>\nline results can still be returned.<br \/>\nWhen the -i -t parameter is used together, you can see the familiar Linux command prompt.<\/p>\n<p>$ docker run -dit ubuntu<br \/>\n16168d4b66b115b5afac5836db3ff93304774e98489f628ac625fff2bcd640ba<\/p>\n<p>$ docker container ls<br \/>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br \/>\n16168d4b66b1 ubuntu &#8220;\/bin\/bash&#8221; 58 seconds ago Up 57 seconds happy_bardeen<\/p>\n<p>$ docker exec -it 16168 bash<br \/>\nroot@16168d4b66b1:\/#<\/p>\n<p>Exit from this stdin will not cause the container to stop. That&#8217;s why the docker exec is recommended.<br \/>\nFor more parameter descriptions, please use docker exec &#8211;help to view.<\/p>\n<p>Fifth, delete the container<\/p>\n<p>Delete a container that is in a terminated state in the format:<br \/>\ndocker container rm [options] CONTAINER [CONTAINER&#8230;]<\/p>\n<p>$ docker container rm awesome_payne<br \/>\nawesome_payne<\/p>\n<p>If you want to delete a running container, you can add the -f parameter. Docker will send a SIGKILL signal to the container.<\/p>\n<p>Clean up all containers in the terminated state. Use the docker container ls -a command to view all the containers that have been created, including the termination status. If the number is too large, it may be cumbersome to delete them one by one. You can use the following command to clear all the termination status. Container.<\/p>\n<p>$ docker container prune<br \/>\nWARNING! This will remove all stopped containers.<br \/>\nAre you sure you want to continue? [y\/N] y<br \/>\nDeleted Containers:<br \/>\n545f8f6d19286efae28307d06ed1acc034d07f109e907c01892471a6f89e772d<br \/>\ncb30b87566d0550ec5f1232d148c5ffed6546c347889e58a6405579f2af73f2a<br \/>\n&#8230;&#8230;<\/p>\n<p>Export and import containers<\/p>\n<p>Exporting a container<br \/>\nIf you want to export a local container, you can use the docker export command.<\/p>\n<p>$ docker container ls -a<br \/>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br \/>\n16168d4b66b1 ubuntu &#8220;\/bin\/bash&#8221; 18 minutes ago Up 18 minutes happy_bardeen<\/p>\n<p>$ docker export 16168d4b66b1 &gt; ubuntu.tar<\/p>\n<p>This will export the container snapshot to a local file.<\/p>\n<p>Import container snapshots<br \/>\ncan be imported as mirrors from the container snapshot file using docker import, for example<\/p>\n<p>$ cat ubuntu.tar | docker import &#8211; test\/ubuntu:v1.0<br \/>\nsha256:91b174fec9ed55d7ebc3d2556499713705f40713458e8594efa114f261d7369a<\/p>\n<p>$ docker image ls<br \/>\nREPOSITORY TAG IMAGE ID CREATED SIZE<br \/>\ntest\/ubuntu v1.0 91b174fec9ed 10 seconds ago 69.8MB<br \/>\nubuntu latest 735f80812f90 3 weeks ago 83.5MB<\/p>\n<p>Alternatively, you can import it by specifying a URL or a directory, such as<br \/>\n$ docker import http:\/\/example.com\/exampleimage.tgz example\/imagerepo<\/p>\n<p>Note: Users can either use the docker load to import the image storage file to the local image library, or use docker import to import a container snapshot to the local image library. The difference between the two is that the container snapshot file will discard all history and metadata information (that is, only the snapshot state of the container at the time), and the image storage file will save the full record and be large. In addition, metadata information such as tags can be reassigned when importing from a container snapshot file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[root@ docker]# cat \/etc\/yum.repos.d\/docker-main.repo [docker-main-repo] name=Docker main Repository baseurl=https:\/\/get.daocloud.io\/docker\/yum-repo\/main\/CentOS\/7 enabled=1 gpgcheck=1 gpgkey=https:\/\/get.daocloud.io\/docker\/yum\/gpg<\/p>\n<p>[root@ docker]# yum install docker-engine \u2013y<\/p>\n<p>[root@ docker]# docker &#8211;version Docker version 17.05.0-ce, build 89658be<\/p>\n<p>firewall-cmd &#8211;add-port=2377\/tcp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=7946\/tcp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=7946\/udp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;add-port=4789\/udp &#8211;permanent<\/p>\n<p>firewall-cmd &#8211;reload**<\/p>\n<p>[root@ docker]# cat \/etc\/docker\/daemon.json { &#8220;insecure-registries&#8221;:[&#8220;docker-registry.rmohan.com:5000&#8221;], &#8220;log-driver&#8221;:&#8221;json-file&#8221;, &#8220;log-opts&#8221;:{&#8220;max-size&#8221;:&#8221;1024m&#8221;,&#8221;max-file&#8221;:&#8221;2&#8243;} }<\/p>\n<p>[root@ ~]# systemctl restart docker.service<\/p>\n<p> [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7724"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7724"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7724\/revisions"}],"predecessor-version":[{"id":7727,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7724\/revisions\/7727"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}