{"id":2415,"date":"2019-09-05T23:41:59","date_gmt":"2019-09-05T23:41:59","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=2415"},"modified":"2020-04-21T12:02:10","modified_gmt":"2020-04-21T12:02:10","slug":"docker-introduction","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=2415","title":{"rendered":"Docker Introduction &#038; Commands"},"content":{"rendered":"<p><a href=\"http:\/\/wiki.thomasandsofia.com\/?p=2423\">Docker run<\/a> &gt;<\/p>\n<h1>Links<\/h1>\n<h3>Download Docker:<\/h3>\n<p><a href=\"http:\/\/docs.docker.com\" target=\"_blank\" rel=\"noopener\">http:\/\/docs.docker.com<\/a>\u00a0(Make sure you open the page wide enough to see the side bar.)<\/p>\n<p><a href=\"https:\/\/docs.docker.com\/install\/linux\/docker-ce\/ubuntu\/\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.docker.com\/install\/linux\/docker-ce\/ubuntu\/<\/a><\/p>\n<h3>Download pre-built images:<\/h3>\n<p><a href=\"http:\/\/hub.docker.com\" target=\"_blank\" rel=\"noopener\">http:\/\/hub.docker.com<\/a><\/p>\n<h1>Introduction<\/h1>\n<h2>5. Setup and Install Docker<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/course\/learn-docker\/learn\/lecture\/7928348#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/course\/learn-docker\/learn\/lecture\/7928348#overview<\/a><\/p>\n<p>Download: <a href=\"https:\/\/docs.docker.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.docker.com\/<\/a> &gt; Get Docker<\/p>\n<p>Ubuntu: <a href=\"https:\/\/docs.docker.com\/engine\/install\/ubuntu\/\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.docker.com\/engine\/install\/ubuntu\/<\/a><\/p>\n<pre>sudo apt update\r\nsudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common\r\n\r\n# Add Docker\u2019s official GPG key:\r\ncurl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -\r\n\r\n# Add stable repository\r\nsudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\"\r\n\r\n# Install Docker\r\nsudo apt update \r\nsudo apt install docker-ce docker-ce-cli containerd.io<\/pre>\n<h2>Using Docker Hub<\/h2>\n<p><a href=\"https:\/\/hub.docker.com\" target=\"_blank\" rel=\"noopener\">https:\/\/hub.docker.com<\/a><\/p>\n<h3>Create your first container &#8211; Whalesay<\/h3>\n<pre>sudo docker run docker\/whalesay cowsay Hello World!<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h1>Docker Commands<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/7894010#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/7894010#overview<\/a><\/p>\n<p>Docker official reference link: <a href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/docker\/\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.docker.com\/engine\/reference\/commandline\/docker\/<\/a><\/p>\n<h2>attach<\/h2>\n<p>Attach to a previously detached container<\/p>\n<pre>docker attach &lt;container_id | container_name&gt;<\/pre>\n<ul>\n<li>When using the container_id, you only need to use the first few characters as long as they are unique to that container!<\/li>\n<\/ul>\n<h2>build<\/h2>\n<p>Builds an image based on the contents of `Dockerfile`<\/p>\n<ul>\n<li>-t Tag: Name the new image<\/li>\n<li>-f file: Defines a file to build from other than the default &#8216;Dockerfile&#8217;<\/li>\n<\/ul>\n<pre>docker build . -f mybuild -t myapp:latest<\/pre>\n<h2>exec<\/h2>\n<p>Runs a command in the container<\/p>\n<pre>docker exec &lt;container_id | container_name&gt; &lt;command&gt;<\/pre>\n<h3>Examples:<\/h3>\n<p>Log into a running container. Type &#8216;exit&#8217; to exit out.<\/p>\n<pre>docker exec -it &lt;container_name&gt; \/bin\/bash<\/pre>\n<p>Display the contents of the \/etc\/hosts file<\/p>\n<pre>docker exec &lt;container_name&gt; cat \/etc\/hosts<\/pre>\n<h2>history<\/h2>\n<p>Lists the steps required to build an image.<\/p>\n<p><em>Discussed in Section 18<\/em><\/p>\n<pre>docker history &lt;ImageName | ImageId&gt;<\/pre>\n<ul>\n<li>Also shows the size of each step<\/li>\n<\/ul>\n<h2>images<\/h2>\n<p>Lists all images available on the system<\/p>\n<pre>docker images<\/pre>\n<h2>inspect<\/h2>\n<p>Prints the information about the container in a JSON format<\/p>\n<p><em>This is actually discussed in the &#8216;Run&#8217; lecture, but is not a run command.<\/em><\/p>\n<pre>docker inspect &lt;ContainerName | ContainerId&gt;<\/pre>\n<ul>\n<li>Great for finding all configuration information about a container\n<ul>\n<li>IP address and port<\/li>\n<li>passwords<\/li>\n<li>status<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>logs<\/h2>\n<p>Display the logs from a Container.<\/p>\n<pre>docker logs &lt;ContainerId | ContainerName&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>ps<\/h2>\n<p>Lists all running containers<\/p>\n<pre>docker ps<\/pre>\n<h3>Options<\/h3>\n<p>-a<br \/>\nInclude all running and previously stopped containers.<\/p>\n<h2>pull<\/h2>\n<p>Downloads a pre-created public image from the docker repository<\/p>\n<pre>docker pull &lt;image_name&gt;<\/pre>\n<ul>\n<li>Only downloads the image.\u00a0 Does not start it as it would if you were pulling using the &#8216;run&#8217; command.<\/li>\n<\/ul>\n<h2>rm<\/h2>\n<p>Removes a container and reclaims the diskspace<\/p>\n<pre>docker remove &lt;container_id | container_name&gt;<\/pre>\n<ul>\n<li>Good for cleaning up history.<\/li>\n<li>list multiple container ids to remove several with one command\n<ul>\n<li>docker rm 123 654 852<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Options<\/h3>\n<p>-f &#8211;force<br \/>\nForces removal of a running container<\/p>\n<p>-v &#8211;volumes<br \/>\nRemoves the volumes associated with a container<\/p>\n<p>-f $(docker ps)<br \/>\nRemoves all running containers<\/p>\n<p>-f ($docker ps -a)<br \/>\nRemoves ALL containers, stopped and running.<\/p>\n<p>$(docker ps -a -q)<br \/>\nRemoves all stopped containers.\u00a0 Has no affect on running containers (an error is generated instead)<\/p>\n<pre>docker rm $(docker -a -q)<\/pre>\n<h2>rmi<\/h2>\n<p>Removes an image from your system<\/p>\n<pre>docker rmi &lt;image_id | image_name&gt;<\/pre>\n<ul>\n<li>You must first remove (not just stop) any containers that are currently running off the image.<\/li>\n<\/ul>\n<h2>run<\/h2>\n<p>Starts a container from an existing image<\/p>\n<pre>docker run &lt;image&gt;<\/pre>\n<ul>\n<li>If you use a non-repository image, you should preface the name with the developer&#8217;s userid:\n<ul>\n<li>thomasr\/myimage<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>Options<\/h4>\n<p>-d Detached<br \/>\nRuns the container in the background<br \/>\n-it<\/p>\n<ul>\n<li>If the image does not exist locally, it will attempt to download it from the Docker repositories.\u00a0 Once downloaded, subsequent &#8216;runs&#8217; on that image will use the local copy.<\/li>\n<li>New containers are automatically provided with a random Container Id and Name.<\/li>\n<\/ul>\n<h3>References<\/h3>\n<p>Ref:<\/p>\n<h2>stop<\/h2>\n<p>Stops a running container.<\/p>\n<pre>docker stop &lt;container_id | container_name&gt;<\/pre>\n<ul>\n<li>Does not remove the container from the system.\u00a0 To remove it, you need to run docker rm &#8230;<\/li>\n<\/ul>\n<h1>Docker Labs<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/15828562#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/15828562#overview<\/a><\/p>\n<ul>\n<li>Recommended to use Chrome browser.<\/li>\n<li>Lab on the left\n<ul>\n<li>Lab environments are deleted after an hour.<\/li>\n<\/ul>\n<\/li>\n<li>Quiz portal on the right.\n<ul>\n<li>if the quiz gets &#8216;stuck&#8217;, break it out from the lab side<\/li>\n<li>if you skip a question, you cannot return to it.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h1>Basic Docker Commands Lab<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/15828568#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/learn-docker\/learn\/lecture\/15828568#overview<\/a><\/p>\n<p>&#8230;start lesson 10<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker run &gt; Links Download Docker: http:\/\/docs.docker.com\u00a0(Make sure you open the page wide enough to see the side bar.) https:\/\/docs.docker.com\/install\/linux\/docker-ce\/ubuntu\/ Download pre-built images: http:\/\/hub.docker.com Introduction 5. Setup and Install Docker https:\/\/www.udemy.com\/course\/learn-docker\/learn\/lecture\/7928348#overview Download: https:\/\/docs.docker.com\/ &gt; Get Docker Ubuntu: https:\/\/docs.docker.com\/engine\/install\/ubuntu\/ sudo apt update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common # Add Docker\u2019s official GPG key: ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=2415\" 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-2415","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2415","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=2415"}],"version-history":[{"count":19,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2415\/revisions"}],"predecessor-version":[{"id":2689,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2415\/revisions\/2689"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}