{"id":2423,"date":"2019-09-08T01:20:12","date_gmt":"2019-09-08T01:20:12","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=2423"},"modified":"2020-04-16T02:21:19","modified_gmt":"2020-04-16T02:21:19","slug":"docker-run","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=2423","title":{"rendered":"3. Docker Run"},"content":{"rendered":"<p><a href=\"http:\/\/wiki.thomasandsofia.com\/?p=2415\" rel=\"noopener\">&lt; 2 Docker Introduction and Commands<\/a> | <a href=\"\/docker-images\/\">4 Docker Images &gt;<\/a><\/p>\n<h1>14. Docker Run<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/7894016#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/7894016#overview<\/a><\/p>\n<p><a href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/run\/\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.docker.com\/engine\/reference\/commandline\/run\/<\/a><\/p>\n<h2>Tags &lt;image&gt;:&lt;tag&gt;<\/h2>\n<pre>&lt;image&gt;:&lt;tag&gt;<\/pre>\n<ul>\n<li>Specify a version of an image by running the image name followed by a colon and then the version number.<\/li>\n<li>If no tag is applied, the default tag is &#8216;latest&#8217;<\/li>\n<\/ul>\n<h3>Links<\/h3>\n<ul>\n<li><a href=\"https:\/\/hub.docker.com\" target=\"_blank\" rel=\"noopener\">https:\/\/hub.docker.com<\/a>\n<ul>\n<li>locate and click the name of the image to view available supported tags.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>-i -it Container Input stdin<\/h2>\n<pre>docker run -it<\/pre>\n<p>-i Maps the standard input (keyboard) to the container<\/p>\n<p>-t &#8216;psudo tty&#8217; allows users to see the standard output from a process.\u00a0 (read text it displays)<\/p>\n<h2>-p &lt;HostPort&gt;:&lt;ContainerPort&gt; Map Ports<\/h2>\n<pre>docker run -p 80:5000 &lt;image&gt;<\/pre>\n<ul>\n<li>Maps the host port to the container port.<\/li>\n<li>Allows you to run multiple containers of the same application and access them via their assigned port<\/li>\n<\/ul>\n<h2>-v &lt;HostPath&gt;:&lt;ContainerPath&gt; Volume mapping<\/h2>\n<p>Used to store and access persistent data.\u00a0 Data not mapped to a persistent drive will be lost when the container stops.<\/p>\n<pre>docker run -v \/opt\/datadir:\/var\/lib\/mysql mysql<\/pre>\n<p>&nbsp;<\/p>\n<h2>docker inspect<\/h2>\n<p>While not a &#8216;run&#8217; command, the &#8216;inspect&#8217; command will display a container&#8217;s [service] definition information in a JSON format.<\/p>\n<pre>$ docker inspect 30ff\r\n[\r\n    {\r\n        \"Id\": \"30ff2dcf37fbebcd6765c0f59252368fc5cf1cadf4a64b8d9cae90a0822c55a9\",\r\n        \"Created\": \"2020-04-15T18:53:51.286558212Z\",\r\n        \"Path\": \"sleep\",\r\n        \"Args\": [\r\n            \"20\"\r\n        ],\r\n        \"State\": {\r\n            \"Status\": \"running\",\r\n            \"Running\": true,\r\n            \"Paused\": false,\r\n            \"Restarting\": false,\r\n            \"OOMKilled\": false,\r\n            \"Dead\": false,\r\n            \"Pid\": 3499,\r\n            \"ExitCode\": 0,\r\n            \"Error\": \"\",\r\n            \"StartedAt\": \"2020-04-15T18:53:51.814429508Z\",\r\n            \"FinishedAt\": \"0001-01-01T00:00:00Z\"\r\n        },\r\n        \"Image\": \"sha256:470671670cac686c7cf0081e0b37da2e9f4f768ddc5f6a26102ccd1c6954c1ee\",\r\n...<\/pre>\n<h2>Container Logs<\/h2>\n<pre>docker logs &lt;container-name&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h1>15. Demo &#8211; Advanced Run Commands<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/course\/learn-docker\/learn\/lecture\/7894024#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/course\/learn-docker\/learn\/lecture\/7894024#overview<\/a><\/p>\n<h2>Running bash commands<\/h2>\n<pre>docker run centos cat \/etc\/*eleas*\r\ncat: \/etc\/lsb-release: No such file or directory\r\nNAME=\"CentOS Linux\"\r\nVERSION=\"8 (Core)\"\r\nID=\"centos\"\r\nID_LIKE=\"rhel fedora\"\r\nVERSION_ID=\"8\"\r\nPLATFORM_ID=\"platform:el8\"\r\nPRETTY_NAME=\"CentOS Linux 8 (Core)\"\r\nANSI_COLOR=\"0;31\"\r\nCPE_NAME=\"cpe:\/o:centos:centos:8\"\r\nHOME_URL=\"https:\/\/www.centos.org\/\"\r\nBUG_REPORT_URL=\"https:\/\/bugs.centos.org\/\"\r\n\r\nCENTOS_MANTISBT_PROJECT=\"CentOS-8\"\r\nCENTOS_MANTISBT_PROJECT_VERSION=\"8\"\r\nREDHAT_SUPPORT_PRODUCT=\"centos\"\r\nREDHAT_SUPPORT_PRODUCT_VERSION=\"8\"\r\n<\/pre>\n<h2>Run a different version using tags from Docker Hub.<\/h2>\n<pre>docker run centos:7 cat \/etc\/*eleas*\r\nUnable to find image 'centos:7' locally\r\n7: Pulling from library\/centos\r\nab5ef0e58194: Pull complete \r\nDigest: sha256:4a701376d03f6b39b8c2a8f4a8e499441b0d567f9ab9d58e4991de4472fb813c\r\nStatus: Downloaded newer image for centos:7\r\ncat: \/etc\/lsb-release: No such file or directory\r\nNAME=\"CentOS Linux\"\r\nVERSION=\"7 (Core)\"\r\nID=\"centos\"\r\nID_LIKE=\"rhel fedora\"\r\nVERSION_ID=\"7\"\r\nPRETTY_NAME=\"CentOS Linux 7 (Core)\"\r\nANSI_COLOR=\"0;31\"\r\nCPE_NAME=\"cpe:\/o:centos:centos:7\"\r\nHOME_URL=\"https:\/\/www.centos.org\/\"\r\nBUG_REPORT_URL=\"https:\/\/bugs.centos.org\/\"\r\n\r\nCENTOS_MANTISBT_PROJECT=\"CentOS-7\"\r\nCENTOS_MANTISBT_PROJECT_VERSION=\"7\"\r\nREDHAT_SUPPORT_PRODUCT=\"centos\"\r\nREDHAT_SUPPORT_PRODUCT_VERSION=\"7\"<\/pre>\n<h2>Run in -d Detached mode<\/h2>\n<p>This will return you to the current session command prompt while keeping the container alive.<\/p>\n<pre>docker run -d centos sleep 1000\r\n6ec5790987e63dd81904daab4c920f456fadc7a465292e069ee5c15ca27405c8<\/pre>\n<p>Forgetting the -d may require you to open a different shell then<\/p>\n<pre>docker stop &lt;container_id&gt;<\/pre>\n<h1>16 Labs<\/h1>\n<h1>17 Reviews<\/h1>\n<h1>18 LinkedIn<\/h1>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt; 2 Docker Introduction and Commands | 4 Docker Images &gt; 14. Docker Run https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/7894016#overview https:\/\/docs.docker.com\/engine\/reference\/commandline\/run\/ Tags &lt;image&gt;:&lt;tag&gt; &lt;image&gt;:&lt;tag&gt; Specify a version of an image by running the image name followed by a colon and then the version number. If no tag is applied, the default tag is &#8216;latest&#8217; Links https:\/\/hub.docker.com locate and click the ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=2423\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-2423","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2423"}],"version-history":[{"count":8,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2423\/revisions"}],"predecessor-version":[{"id":2664,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2423\/revisions\/2664"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}