{"id":801,"date":"2023-08-13T15:52:52","date_gmt":"2023-08-13T10:22:52","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=801"},"modified":"2024-04-02T15:17:46","modified_gmt":"2024-04-02T09:47:46","slug":"docker-basic-commands","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=801","title":{"rendered":"Docker Basic Commands"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>Docker Basic Commands<\/strong><\/span><\/p>\n<p><strong>Youtube link:<\/strong> <span style=\"color: #3366ff;\"><a style=\"color: #3366ff;\" href=\"https:\/\/www.youtube.com\/watch?v=bPFWCOQjG_I&amp;list=PLwO9EbabNLzuiIWvsG2ZgK2s4JQOZyfaJ&amp;index=7\">Navigation for lab<\/a><\/span><\/p>\n<pre>docker search nginx<\/pre>\n<p>\/\/ Docker images related to Nginx that are available on Docker Hub.<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-814\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search-300x71.png\" alt=\"\" width=\"300\" height=\"71\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search-300x71.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search-700x165.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search-768x181.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/search.png 1147w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker pull nginx<\/pre>\n<p>\/\/ This command will download the latest version of the official Nginx image from Docker Hub and make it available on your local machine for running containers. If you want a specific version of the Nginx image, you can specify the version tag after the image name.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-807\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull-300x49.png\" alt=\"\" width=\"300\" height=\"49\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull-300x49.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull-700x115.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull-768x126.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/pull.png 944w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker images<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/images.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-804\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/images-300x27.png\" alt=\"\" width=\"300\" height=\"27\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/images-300x27.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/images.png 678w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker run &lt;image name&gt;: will run the container<\/pre>\n<p>\/\/ Running the docker run nginx command will start a new container using the official Nginx image from Docker Hub. However, by default, this command will start the container in the foreground, which means the terminal will be attached to the container&#8217;s output, and you won&#8217;t be able to use the terminal for other commands until you stop the container.<\/p>\n<pre>Press Ctrl+C to exit<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-811\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run-300x67.png\" alt=\"\" width=\"300\" height=\"67\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run-300x67.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run-700x156.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run-768x171.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/run.png 1126w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker run -it nginx \/bin\/bash<\/pre>\n<p>\/\/ docker run -it nginx \/bin\/bash, attempts to start a new container based on the Nginx image and then launch an interactive bash shell within that container.<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/runit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-813\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/runit-300x85.png\" alt=\"\" width=\"300\" height=\"85\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/runit-300x85.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/runit.png 648w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>Exit from the console of container, Type \"exit\" command<\/pre>\n<pre>docker run -d nginx<\/pre>\n<p>\/\/Running the command docker run -d nginx will start a new Docker container using the official Nginx image in detached mode. This means the container will run in the background and won&#8217;t be attached to your terminal.<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-812\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund-300x34.png\" alt=\"\" width=\"300\" height=\"34\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund-300x34.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund-700x79.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund-768x86.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rund.png 1076w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker ps<\/pre>\n<p>\/\/The docker ps command is used to list the currently running Docker containers on your system.<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-806\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps-300x24.png\" alt=\"\" width=\"300\" height=\"24\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps-300x24.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps-700x56.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps-768x62.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/ps.png 861w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker stop &lt;container id\/ container name&gt;<\/pre>\n<p>\/\/ Absolutely, you can use the docker stop command to stop a running Docker container. You can specify either the container&#8217;s ID or its name to identify the container you want to stop.<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-815\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop-300x49.png\" alt=\"\" width=\"300\" height=\"49\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop-300x49.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop-700x114.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop-768x125.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/stop.png 910w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker rename &lt;old name&gt; &lt;new name&gt;<\/pre>\n<p>\/\/Rename the container<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-808\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename-300x43.png\" alt=\"\" width=\"300\" height=\"43\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename-300x43.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename-700x100.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename-768x110.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rename.png 927w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker restart\u00a0 &lt;container id&gt;<\/pre>\n<p>\/\/restart the container<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-809\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart-300x31.png\" alt=\"\" width=\"300\" height=\"31\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart-300x31.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart-700x72.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart-768x79.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/restart.png 968w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker exec -it mynginx bash<\/pre>\n<p>\/\/ execute any command on the running container, name of the container or provide container id<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-802\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec-300x36.png\" alt=\"\" width=\"300\" height=\"36\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec-300x36.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec-700x84.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec-768x92.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/exec.png 1092w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>docker logs &lt;container id\/container name&gt;<\/pre>\n<p>\/\/check the logs for running container<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-805\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs-300x66.png\" alt=\"\" width=\"300\" height=\"66\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs-300x66.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs-700x153.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs-768x168.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/logs.png 1127w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>The docker ps -a command lists all Docker containers, both running and stopped, along with their details.<\/strong><\/p>\n<pre>docker rm &lt;container id\/ container name&gt;<\/pre>\n<p>\/\/This will allow you to remove the stopped container<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-810\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm-300x51.png\" alt=\"\" width=\"300\" height=\"51\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm-300x51.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm-700x119.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm-768x131.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rm.png 1366w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Sign-up for docker hub<\/strong><\/p>\n<p><a href=\"https:\/\/hub.docker.com\/signup\">https:\/\/hub.docker.com\/signup<\/a><\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hub.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-803\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hub-286x300.png\" alt=\"\" width=\"286\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hub-286x300.png 286w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hub.png 506w\" sizes=\"auto, (max-width: 286px) 100vw, 286px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker Basic Commands Youtube link: Navigation for lab docker search nginx \/\/ Docker images related to Nginx that are available on Docker Hub. docker pull nginx \/\/ This command will download the latest version of the official Nginx image from Docker Hub and make it available on your local machine for running containers. If you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-801","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=801"}],"version-history":[{"count":5,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/801\/revisions"}],"predecessor-version":[{"id":1411,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/801\/revisions\/1411"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}