{"id":1748,"date":"2020-03-24T20:13:30","date_gmt":"2020-03-25T03:13:30","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=1748"},"modified":"2020-03-24T20:13:30","modified_gmt":"2020-03-25T03:13:30","slug":"docker-basics","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=1748","title":{"rendered":"Docker Basics"},"content":{"rendered":"<p>OS: CentOS 7<br \/>\nInstall Docker:<\/p>\n<blockquote><p># yum install docker-ce-cli docker-ce<\/p><\/blockquote>\n<p>Start Docker:<\/p>\n<blockquote><p># systemctl start docker<\/p><\/blockquote>\n<p>Help:<\/p>\n<blockquote><p># docker &#8211;help<\/p><\/blockquote>\n<p>You can tack on a &#8211;help on the end of any command to get help of that specific option:<\/p>\n<blockquote><p># docker pull &#8211;help<\/p><\/blockquote>\n<p>Pull in an image from hub.docker.com:<\/p>\n<blockquote><p># docker pull ubuntu<\/p><\/blockquote>\n<p>To list your installed images and obtain the IMAGE ID:<\/p>\n<blockquote><p># docker images<\/p><\/blockquote>\n<p>To run an image:<\/p>\n<blockquote><p># docker run -it -d  ubuntu<\/p><\/blockquote>\n<p>To view running images:<\/p>\n<blockquote><p># docker ps<\/p><\/blockquote>\n<p>To stop a running container:<\/p>\n<blockquote><p># docker stop &#8216;<em>CONTAINTER ID<\/em>&#8216;<\/p><\/blockquote>\n<p>To execute a command in a container (In this case, bash in the ubuntu image.):<\/p>\n<blockquote><p># docker exec -it &#8216;<em>CONTAINTER ID<\/em>&#8216; bash<\/p><\/blockquote>\n<p>To view all container, including those that are not running:<\/p>\n<blockquote><p># docker ps -a<\/p><\/blockquote>\n<p>To remove a container:<\/p>\n<blockquote><p># docker rm &#8216;<em>CONTAINTER ID<\/em>&#8216;<\/p><\/blockquote>\n<p>To remove an image:<br \/>\n# docker rmi &#8216;<em>IMAGE ID<\/em>&#8216;<\/p>\n<p>To stop and remove a running container:<\/p>\n<blockquote><p># docker rm -f &#8216;<em>CONTAINTER ID<\/em>&#8216;<\/p><\/blockquote>\n<p>To save changes to a container:<\/p>\n<blockquote><p># docker commit &#8216;<em>CONTAINTER ID<\/em>&#8216; &#8216;<em>NEW IMAGE NAME<\/em>&#8216;<\/p><\/blockquote>\n<p>To remove all running containers:<\/p>\n<blockquote><p># docker rm -f $(docker ps -a -q)<\/p><\/blockquote>\n<p>NOTE: INSTANCE ID can refer an image or container.  The next two command will return the information in json format.<br \/>\nTo view a container&#8217;s history:<\/p>\n<blockquote><p># docker history &#8216;<em>INSTANCE ID<\/em>&#8216;<\/p><\/blockquote>\n<p>To view information about a container:<\/p>\n<blockquote><p># docker inspect &#8216;<em>INSTANCE ID<\/em>&#8216;<\/p><\/blockquote>\n<p>If you want to upload your container to hub.docker.com the container must have a name in the following format:<\/p>\n<blockquote><p># docker commit &#8216;<em>CONTAINTER ID<\/em>&#8216; &#8216;dockerhubuserid&#8217;\/&#8217;newimagename&#8217;<\/p><\/blockquote>\n<p>To run a container and map a host port to the container port:<\/p>\n<blockquote><p># docker run -it -d -p 82:80 jgz\/apache2<\/p><\/blockquote>\n<p>Then, in this case, I would access my container web server from my LAN by accessing my docker host name and the port 82.  So, if my hostname is jims.domain.local, the I would browse to http:\/\/jims.domain.local:82.<\/p>\n<p>A Dockerfile is how you can create a container and run some commands when you start it up:<br \/>\nBuilding a Dockerfile (YAML file):<\/p>\n<blockquote><p># mkdir \/usr\/local\/docker<br \/>\n# cd \/usr\/local\/docker\/<br \/>\n# vi Dockerfile<br \/>\n&#8230;<br \/>\nFROM ubuntu<br \/>\nRUN apt-get update<br \/>\nRUN apt-get -y install apache2<br \/>\nADD . \/var\/www\/html<br \/>\nENTRYPOINT apachectl -D FOREGROUND<br \/>\nENV name jgz<\/p><\/blockquote>\n<p>This will build the container and execute the RUN commands and ENTRYPOINT command:<\/p>\n<blockquote><p># docker build . -t new_dockerfile<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>OS: CentOS 7 Install Docker: # yum install docker-ce-cli docker-ce Start Docker: # systemctl start docker Help: # docker &#8211;help You can tack on a &#8211;help on the end of any command to get help of that specific option: # docker pull &#8211;help Pull in an image from hub.docker.com: # docker pull ubuntu To list [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[494],"class_list":["post-1748","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-docker"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1748"}],"version-history":[{"count":11,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1748\/revisions"}],"predecessor-version":[{"id":1800,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1748\/revisions\/1800"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}