{"id":7015,"date":"2017-09-21T15:38:05","date_gmt":"2017-09-21T07:38:05","guid":{"rendered":"http:\/\/rmohan.com\/?p=7015"},"modified":"2017-09-21T15:38:05","modified_gmt":"2017-09-21T07:38:05","slug":"docker-commonly-used-command","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7015","title":{"rendered":"docker commonly used command"},"content":{"rendered":"<p><strong>docker commonly used command<\/strong><\/p>\n<p>1. View the docker information (version, info)<\/p>\n<p>View the docker version<br \/>\ndocker version  <\/p>\n<p>Displays information about the docker system<br \/>\ndocker info  <\/p>\n<p>2. the operation of the image (search, pull, images, rmi, history)<\/p>\n<p>Retrieve image<br \/>\ndocker search image_name  <\/p>\n<p>Download image<br \/>\ndocker pull image_name<\/p>\n<p>List the mirror list; -a, &#8211;all = false Show all images; &#8211;no-trunc = false Do not truncate output; -q, &#8211;quiet = false Only show numeric IDs  <\/p>\n<p>docker images<\/p>\n<p>Delete one or more mirrors; -f, &#8211;force = false Force; &#8211;no-prune = false Do not delete untagged parents  <\/p>\n<p>docker rmi image_name <\/p>\n<p>Show a history of a mirror; &#8211;no-trunc = false Do not truncate output; -q, &#8211;quiet = false Only show numeric IDs  <\/p>\n<p>docker history image_name  <\/p>\n<p>3. Start the container<\/p>\n<p>The docker container can be understood as a process that runs in a sandbox.<\/p>\n<p>This sandbox contains the resources necessary for the process to run, including the file system, system class library, shell environment and so on.<br \/>\nBut this sandbox by default is not running any program. You need to run a process in the sandbox to start a container.<br \/>\nThis process is the only process of the container, so when the process ends, the container will be completely stopped.<\/p>\n<p>Run the &#8220;echo&#8221; command in the container, output &#8220;hello word&#8221;<br \/>\ndocker run image_name echo &#8220;hello word&#8221; <\/p>\n<p>docker run -i -t image_name \/bin\/bash  <\/p>\n<p>docker run image_name apt-get install -y app_name  <\/p>\n<p>When executing the apt-get command, bring the -y parameter.<br \/>\nIf you do not specify the -y parameter, the apt-get command will enter the interactive mode, requiring the user to enter a command to confirm, but in the docker environment is unable to respond to this interaction.<br \/>\nAfter the apt-get command completes, the container stops, but changes to the container are not lost.<\/p>\n<p>4. View container (ps)<\/p>\n<p>List all currently running containers <\/p>\n<p>docker ps  <\/p>\n<p>List all the containers  <\/p>\n<p>docker ps -a  <\/p>\n<p>List the containers that were last started  <\/p>\n<p>docker ps -l  <\/p>\n<p>5. Save the container to commit (commit)<\/p>\n<p>When you have made a change to a container (by running a command in the container), you can save the container changes, so that the next time you can save the latest state from the container.<\/p>\n<p>Save the changes to the container; -a, &#8211;author = &#8220;&#8221; Author; -m, &#8211;message = &#8220;&#8221; Commit message<br \/>\ndocker commit ID new_image_name<br \/>\nimage is equivalent to the class, container equivalent to the example, but can be dynamically installed to the instance of the new software, and then use the commit order solidified into an image.<\/p>\n<p>6. the operation of the container (rm, stop, start, kill, logs, diff, top, cp, restart, attach)<\/p>\n<p>Remove all containers  <\/p>\n<p>docker rm `docker ps -a -q`<\/p>\n<p>Remove a single container; -f, &#8211;force = false; -l, &#8211;link = false Remove the specified link and not the underlying container; -v, &#8211;volumes = false Remove the volumes associated to the container  <\/p>\n<p>docker rm name \/ id  <\/p>\n<p>Stop, start, kill a container<\/p>\n<p>docker stop Name\/ID<br \/>\ndocker start Name\/ID<br \/>\ndocker kill Name\/ID  <\/p>\n<p>Fetching from a container; -f, &#8211;follow = false Follow log output; -t, &#8211;timestamps = false Show timestamps  <\/p>\n<p>docker logs Name\/ID  <\/p>\n<p>List a file or directory that is changed inside a container. The list list shows three events, A added, D deleted, C changed  <\/p>\n<p>docker diff Name\/ID  <\/p>\n<p>Displays the process information inside a running container  <\/p>\n<p>docker top Name\/ID  <\/p>\n<p>Copy the file \/ directory from the inside of the container to a local path  <\/p>\n<p>docker cp Name:\/container_path to_path<br \/>\ndocker cp ID:\/container_path to_path  <\/p>\n<p>Restart a running container; -t, &#8211;time = 10 Number of seconds to try to stop for before killing the container, Default = 10  <\/p>\n<p>docker restart Name\/ID  <\/p>\n<p>Attached to a running container; &#8211;no-stdin = false Do not attach stdin; &#8211;sig-proxy = true Proxify all received signal to the process  <\/p>\n<p>docker attach ID<br \/>\nThe attach command allows you to view or affect a running container. You can attach the same container at the same time. You can also get out of a container, from CTRL-C.<\/p>\n<p>7. Save and load the mirror (save, load)<\/p>\n<p>When you need to migrate a mirror image to another machine, you need to save the image and load the mirror.<\/p>\n<p>Save the mirror to a tar package; -o, &#8211;output = &#8220;&#8221; Write to an file<br \/>\ndocker save image_name -o file_path<br \/>\nLoad a tarball format image; -i, &#8211;input = &#8220;&#8221; Read from a tar archive file  <\/p>\n<p>docker load -i file_path <\/p>\n<p>docker save image_name -o file_path  <\/p>\n<p>docker load -i file_path<\/p>\n<p>Machine a<br \/>\ndocker save image_name> \/home\/save.tar<br \/>\nUse scp will copy.tar Kaodao machine b, and then:<br \/>\ndocker load <\/home\/save.tar  \n\n\ndocker save image_name > \/home\/save.tar  <\/p>\n<p>docker load < \/home\/save.tar  \n\n\ndocker push new_image_name \n\n\n\n8, log on registry server (login)\n\nLogin server server; -e, - email = \"\" Email; -p, --password = \"\" Password; -u, --username = \"\" Username  \ndocker login  \n\n9. release image (push)\n\nPublish docker image  \ndocker push new_image_name \n\n\n\n10. Use skills\nRemove all containers and mirrors (clean)\nUse a line command to clean up:\n  docker ls $ (docker ps -a -q); docker rmi $ (docker images -q -a) \nNote: The shell in the $ () and `` similar to the implementation of the contents of the inside, the above script will appear as follows docker \"kill\" container, docker rmi Delete the mirror\nWhen there is no running container or no container at all, this will only prompt a warning message. When you want to try, this is a very good single line command. If you just want to delete all the containers, you can run the following command:\ndocker kill $ (docker ps-a); docker rm $ (docker ps -a -q) \n\ndocker kill $(docker ps -q) ; docker rm $(docker ps -a -q) ; docker rmi $(docker images -q -a) \n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>docker commonly used command<\/p>\n<p>1. View the docker information (version, info)<\/p>\n<p>View the docker version docker version <\/p>\n<p>Displays information about the docker system docker info <\/p>\n<p>2. the operation of the image (search, pull, images, rmi, history)<\/p>\n<p>Retrieve image docker search image_name <\/p>\n<p>Download image docker pull image_name<\/p>\n<p>List the mirror list; -a, &#8211;all [&#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\/7015"}],"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=7015"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7015\/revisions"}],"predecessor-version":[{"id":7016,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7015\/revisions\/7016"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}