{"id":2486,"date":"2022-04-07T00:34:02","date_gmt":"2022-04-07T08:34:02","guid":{"rendered":"https:\/\/tungle.ca\/?p=2486"},"modified":"2022-12-04T19:00:37","modified_gmt":"2022-12-05T03:00:37","slug":"building-a-customized-docker-image-using-docker-compose","status":"publish","type":"post","link":"https:\/\/tungle.ca\/?p=2486","title":{"rendered":"Building a customized Docker image using Docker compose"},"content":{"rendered":"\n<p>In this lab, I will explain how to use Docker compose to build your customized Docker image.<\/p>\n\n\n\n<p>+ Create your sample docker file.<\/p>\n\n\n\n<p>This tells Docker to:<br>Build an image starting with the Debian 10 image.<br>Label the container with your email address.<br>Install Apache web service and PHP module.<br>Remove the default index.html on the Apache web server document root directory.<br>Copy a new index.php file and your customized image to the Apache document root directory on the docker container.<br>Run the command hostname and apachectl -DFOREGROUND runs in the foreground.<br>Image to describe that the container is listening on port 80.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker\">root@docker01:~# cat Dockerfile \nFROM debian:10\nLABEL maintainer=\"xyz@my.bcit.ca\"\n#COPY index.php \/usr\/local\/apache2\/htdocs\n#COPY index.php \/var\/www\/html\n#RUN apt-get update &amp;&amp; apt-get -y install apache2\nRUN apt update &amp;&amp; apt -y install apt-utils systemd &amp;&amp; apt-get -y install libapache2-mod-php\nRUN rm \/var\/www\/html\/index.html\nCOPY index.php \/var\/www\/html\nCOPY tung.jpg \/var\/www\/html\n#CMD apachectl -D FOREGROUND\nCMD hostname TungA012345678 &amp;&amp; apachectl -D FOREGROUND\nEXPOSE 80<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"263\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-82.png\" alt=\"\" class=\"wp-image-2494\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-82.png 862w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-82-300x92.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-82-768x234.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-82-200x61.png 200w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/figure>\n\n\n\n<p>+ Create an index.php file with your customized information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">root@docker01:~# cat index.php \n&lt;?php\n$yourname = \"Tung Blog!\";\n$yourstudentnumber = \"A123456789\";\n$image=\"tung.jpg\"; \/\/ this must be included and uploaded as yourpic.jpg in your docker image (Dockerfile)\n$uname=php_uname();\n$all_your_output = &lt;&lt;&lt;HTML\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"utf-8\"\/&gt;\n&lt;title&gt;$yourname - $yourstudentnumber&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;$yourname - $yourstudentnumber&lt;\/h1&gt;\n&lt;img src=\"\/$image\"&gt;\n&lt;div&gt;$uname&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;html&gt;\nHTML;\necho $all_your_output;\n?&gt;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"855\" height=\"366\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-83.png\" alt=\"\" class=\"wp-image-2495\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-83.png 855w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-83-300x128.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-83-768x329.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-83-200x86.png 200w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" \/><\/figure>\n\n\n\n<p>+ Build your app with Docker Compose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker\">docker build -t tung-a01234567 .<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-84.png\" alt=\"\" class=\"wp-image-2496\" width=\"840\" height=\"487\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-84.png 859w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-84-300x174.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-84-768x446.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-84-200x116.png 200w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p>+ Run your app with Docker compose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker\">docker run -d -p 80:80 --cap-add sys_admin -dit tung-a01234567\n---\n-- -d starts docker in daemon mode, in the foreground.\n-- -d p 80:80 listening the port 80 on docker container \n-- -cap-add sys_admin: basically root access to the host.\n-- -dit: it is used for getting access to terminal inside a docker container. In this example is tung-a01234567.<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"446\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-85.png\" alt=\"\" class=\"wp-image-2497\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-85.png 865w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-85-300x155.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-85-768x396.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-85-200x103.png 200w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p>Check your application is running on a Docker container.<\/p>\n\n\n\n<p>docker container ps -a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"838\" height=\"153\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-86.png\" alt=\"\" class=\"wp-image-2498\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-86.png 838w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-86-300x55.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-86-768x140.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-86-200x37.png 200w\" sizes=\"auto, (max-width: 838px) 100vw, 838px\" \/><\/figure>\n\n\n\n<p>Connect to the Apache website with PHP module on the docker container.<\/p>\n\n\n\n<p>http:\/\/192.168.5.46\/index.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-88.png\" alt=\"\" class=\"wp-image-2500\" width=\"578\" height=\"416\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-88-300x217.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-88-200x145.png 200w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this lab, I will explain how to use Docker compose to build your customized Docker image. + Create your sample docker file. This tells Docker to:Build an image starting with the Debian 10 image.Label the container with your email address.Install Apache web service and PHP module.Remove the default index.html on the Apache web server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,28],"tags":[20,26],"class_list":["post-2486","post","type-post","status-publish","format-standard","hentry","category-cloud","category-docker","tag-cloud","tag-docker"],"_links":{"self":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/2486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2486"}],"version-history":[{"count":11,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/2486\/revisions"}],"predecessor-version":[{"id":4428,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/2486\/revisions\/4428"}],"wp:attachment":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}