{"id":1841,"date":"2022-04-19T21:36:16","date_gmt":"2022-04-19T19:36:16","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1841"},"modified":"2022-04-21T08:41:12","modified_gmt":"2022-04-21T06:41:12","slug":"docker-php-application-example","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2022\/04\/19\/docker-php-application-example\/","title":{"rendered":"How to Dockerize  Php Application"},"content":{"rendered":"\n<p>We can run php application using docker. In the following steps, we are creating and running php application.<\/p>\n\n\n\n<ol><li><strong>Create a directory<\/strong><\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code> $ mkdir php-docker-app  \n $ cd php-docker-app  <\/code><\/pre>\n\n\n\n<p>2.  <strong>Create a Php File<\/strong> (in the directory)<\/p>\n\n\n\n<p><strong>\/\/ index.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php  \n    echo ?Hello, Php?;  \n?&gt;  <\/code><\/pre>\n\n\n\n<p>3. <strong>Create a DockerFile<\/strong><\/p>\n\n\n\n<p><strong>\/\/ Dockefile<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM php:7.0-apache  \nCOPY . \/var\/www\/php  <\/code><\/pre>\n\n\n\n<p>After that our project has two files like the below screen-shot :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-27.png\" alt=\"\" class=\"wp-image-1843\" width=\"494\" height=\"113\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-27.png 787w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-27-300x69.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-27-768x176.png 768w\" sizes=\"(max-width: 494px) 100vw, 494px\" \/><\/figure><\/div>\n\n\n\n<p>4.  <strong>Create Docker Image<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t php-app .  <\/code><\/pre>\n\n\n\n<p>In the below screen-shot, we are creating docker image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-28.png\" alt=\"\" class=\"wp-image-1844\" width=\"666\" height=\"393\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-28.png 946w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-28-300x177.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-28-768x454.png 768w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure>\n\n\n\n<p>Now look for the available images in the docker container.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-29.png\" alt=\"\" class=\"wp-image-1845\" width=\"662\" height=\"77\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-29.png 976w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-29-300x35.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-29-768x90.png 768w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/figure>\n\n\n\n<p>The above screen-shot shows that the created image&nbsp;<strong>php-app<\/strong>&nbsp;is available.<\/p>\n\n\n\n<p>5. <strong>Run the Docker image<\/strong><\/p>\n\n\n\n<p>Now run the docker image. The following command is used to run docker images.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker run php-app  <\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-31.png\" alt=\"\" class=\"wp-image-1848\" width=\"747\" height=\"201\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-31.png 994w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-31-300x81.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-31-768x207.png 768w\" sizes=\"(max-width: 747px) 100vw, 747px\" \/><\/figure><\/div>\n\n\n\n<p>We can see that our docker image is running and output is shown to the browser. This image is running on the&nbsp;<strong>172.17.0.2 ip.<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-30.png\" alt=\"\" class=\"wp-image-1846\" width=\"723\" height=\"309\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-30.png 977w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-30-300x128.png 300w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/04\/image-30-768x329.png 768w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5>Reference:<\/h5>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/docker-php-example\">https:\/\/www.javatpoint.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can run php application using docker. In the following steps, we are creating and running php application. Create a directory 2. Create a Php File (in the directory) \/\/ index.php 3. Create a DockerFile \/\/ Dockefile After that our project has two files like the below screen-shot : 4. Create Docker Image In the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1850,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[533],"tags":[182,180,54,291],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1841"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1841"}],"version-history":[{"count":4,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1841\/revisions"}],"predecessor-version":[{"id":1861,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1841\/revisions\/1861"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1850"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}