{"id":3102,"date":"2022-04-19T08:57:15","date_gmt":"2022-04-19T16:57:15","guid":{"rendered":"https:\/\/tungle.ca\/?p=3102"},"modified":"2022-12-04T18:57:44","modified_gmt":"2022-12-05T02:57:44","slug":"building-a-customized-docker-image-using-docker-compose-on-aws","status":"publish","type":"post","link":"https:\/\/tungle.ca\/?p=3102","title":{"rendered":"Building a customized Docker image using Docker compose on AWS"},"content":{"rendered":"\n<p>This is a diagram that I have used for this lab.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"556\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-598.png\" alt=\"\" class=\"wp-image-3165\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-598.png 547w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-598-295x300.png 295w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-598-197x200.png 197w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/figure>\n\n\n\n<p>I have explained how to build a customized Docker image using Docker compose on-prem (<a href=\"https:\/\/tungle.ca\/?p=2486\">https:\/\/tungle.ca\/?p=2<\/a>486). In this post, I will build a customized Docker image using Docker compose on AWS, then deploy WordPress via this docker container.<\/p>\n\n\n\n<p>+ Create a new Debian Linux instance on AWS. Then, SSH to the instance and check Debian&#8217;s host version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">lsb_release -a<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"240\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-554.png\" alt=\"\" class=\"wp-image-3104\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-554.png 759w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-554-300x95.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-554-200x63.png 200w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><\/figure>\n\n\n\n<p>+ Create an index.php file with your customized information.<\/p>\n\n\n\n<p>nano index.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&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=\"732\" height=\"363\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-555.png\" alt=\"\" class=\"wp-image-3105\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-555.png 732w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-555-300x149.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-555-200x99.png 200w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/figure>\n\n\n\n<p>Download a free .jpg image from the Internet and change it to tung.jpg<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"59\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-556.png\" alt=\"\" class=\"wp-image-3106\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-556.png 362w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-556-300x49.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-556-200x33.png 200w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><figcaption class=\"wp-element-caption\">Create your sample docker file.<\/figcaption><\/figure>\n\n\n\n<p>This tells Docker to:<br>&#8211; Build an image starting with the Debian 10 image.<br>&#8211; Label the container with your email address.<br>&#8211; Install Apache web service and PHP module.<br>&#8211; Remove the default index.html on the Apache web server document root directory.<br>&#8211; Copy a new index.php file and your customized image to the Apache document root directory on the docker container.<br>&#8211; Run the command hostname and apachectl -DFOREGROUND runs in the foreground.<br>&#8211; Image to describe that the container is listening on port 80.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">nano Dockerfile<\/code><\/pre>\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=\"771\" height=\"243\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-557.png\" alt=\"\" class=\"wp-image-3107\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-557.png 771w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-557-300x95.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-557-768x242.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-557-200x63.png 200w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/figure>\n\n\n\n<p>+ Build your app with Docker Compose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">docker build -t tung-a0123456789 .<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"483\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/05\/image-55.png\" alt=\"\" class=\"wp-image-3756\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/05\/image-55.png 907w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/05\/image-55-300x160.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/05\/image-55-768x409.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/05\/image-55-200x107.png 200w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"537\" height=\"351\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-559.png\" alt=\"\" class=\"wp-image-3109\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-559.png 537w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-559-300x196.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-559-200x131.png 200w\" sizes=\"auto, (max-width: 537px) 100vw, 537px\" \/><\/figure>\n\n\n\n<p>Run your app with Docker compose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">docker run -d -p 80:80 --cap-add sys_admin -dit tung-a0123456789<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker\">---\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-a0123456789.<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"53\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-560.png\" alt=\"\" class=\"wp-image-3110\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-560.png 759w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-560-300x21.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-560-200x14.png 200w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><\/figure>\n\n\n\n<p>Check that port 80 is running on the docker container.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">netstat -antp | grep 80<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"844\" height=\"69\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-561.png\" alt=\"\" class=\"wp-image-3111\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-561.png 844w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-561-300x25.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-561-768x63.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-561-200x16.png 200w\" sizes=\"auto, (max-width: 844px) 100vw, 844px\" \/><\/figure>\n\n\n\n<p>+ Check your application is running on a Docker container.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">docker container ps -a<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"143\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-562.png\" alt=\"\" class=\"wp-image-3112\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-562.png 895w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-562-300x48.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-562-768x123.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-562-200x32.png 200w\" sizes=\"auto, (max-width: 895px) 100vw, 895px\" \/><\/figure>\n\n\n\n<p>Connect to the Apache website with the PHP module on the docker container (http:\/\/3.239.117.185)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"981\" height=\"817\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-563.png\" alt=\"\" class=\"wp-image-3113\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-563.png 981w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-563-300x250.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-563-768x640.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-563-200x167.png 200w\" sizes=\"auto, (max-width: 981px) 100vw, 981px\" \/><\/figure>\n\n\n\n<p>A few commands to use for checking the docker container.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"docker\" class=\"language-docker\">docker ps -a\ndocker images\ndocker container ps -a\ndocker stop \"Container ID\"\ndocker rm \"Container ID\"\ndocker image rm \"ImageID\"<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"496\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-564.png\" alt=\"\" class=\"wp-image-3114\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-564.png 980w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-564-300x152.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-564-768x389.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/04\/image-564-200x101.png 200w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a diagram that I have used for this lab. I have explained how to build a customized Docker image using Docker compose on-prem (https:\/\/tungle.ca\/?p=2486). In this post, I will build a customized Docker image using Docker compose on AWS, then deploy WordPress via this docker container. + Create a new Debian Linux instance [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,28],"tags":[20,26],"class_list":["post-3102","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\/3102","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=3102"}],"version-history":[{"count":8,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/3102\/revisions"}],"predecessor-version":[{"id":4425,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/3102\/revisions\/4425"}],"wp:attachment":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}