{"id":783,"date":"2019-01-19T06:39:01","date_gmt":"2019-01-19T06:39:01","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=783"},"modified":"2019-07-19T06:44:34","modified_gmt":"2019-07-19T06:44:34","slug":"docker-container-build-images-from-a-container","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=783","title":{"rendered":"Docker container: Build images from a container"},"content":{"rendered":"<p>Like we can create an image from a Dockerfile, we can create a container from an image too.<\/p>\n<p>The steps to do that is as follows:<\/p>\n<p>Deploy a container from an image:<\/p>\n<p><em><strong>[root@gw20-lap-doc1 sandbox]# docker run -it centos \/bin\/bash<\/strong><\/em><\/p>\n<p>Now\u00a0create a new folder in the container:<\/p>\n<p><em><strong>[root@4bab5b1c66ed \/]# mkdir \/My_New_Folder<\/strong><\/em><\/p>\n<p>Check if the folder got created by running a\u00a0<em><strong>ls<\/strong><\/em> command.<\/p>\n<p><em><strong>[root@4bab5b1c66ed \/]#\u00a0yum install redis -y<\/strong><\/em><\/p>\n<p>This will install\u00a0 httpd service.<\/p>\n<p>Now open another terminal window connecting to your host where the docker is running and run the following command:<\/p>\n<p><em><strong>[root@gw20-lap-doc1 ~]# docker ps -all<\/strong><\/em><\/p>\n<p>Identify the container ID of the container running in the other terminal window. In my system the one I can find is\u00a0<strong><em>4bab5b1c66ed<\/em><\/strong><\/p>\n<p>Now run the following command:<\/p>\n<p><em><strong>[root@gw20-lap-doc1 ~]# docker commit 4bab5b1c66ed shiju_centos_2<\/strong><\/em><\/p>\n<p>Just create an image<\/p>\n<p><em><strong>[root@gw20-lap-doc1 ~]# docker commit -c &#8216;CMD [&#8220;redis-server&#8221;]&#8217; 4bab5b1c66ed shiju_centos_3<\/strong><\/em><\/p>\n<p>Create an image an execute the command to start redis server in the container that will be deployed using the image.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Like we can create an image from a Dockerfile, we can create a container from an image too. The steps to do that is as <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=783\" title=\"Docker container: Build images from a container\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":730,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,25],"tags":[],"class_list":["post-783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-docker"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=783"}],"version-history":[{"count":4,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/783\/revisions"}],"predecessor-version":[{"id":848,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/783\/revisions\/848"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/730"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=783"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}