<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Concatly</title>
    <description>The latest articles on DEV Community by Concatly (@concatly).</description>
    <link>https://dev.to/concatly</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F173558%2F337b5ab3-7d08-41fb-9ad1-fe483172a5e2.jpg</url>
      <title>DEV Community: Concatly</title>
      <link>https://dev.to/concatly</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/concatly"/>
    <language>en</language>
    <item>
      <title>How to Dockerize a Basic PHP Application?</title>
      <dc:creator>Concatly</dc:creator>
      <pubDate>Thu, 30 May 2019 11:24:41 +0000</pubDate>
      <link>https://dev.to/concatly/how-to-deploy-a-dockerize-a-basic-php-application-4756</link>
      <guid>https://dev.to/concatly/how-to-deploy-a-dockerize-a-basic-php-application-4756</guid>
      <description>&lt;h1&gt;
  
  
  What is Docker?
&lt;/h1&gt;

&lt;p&gt;Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. &lt;/p&gt;

&lt;h1&gt;
  
  
  Steps for Dockerizing a Basic PHP Application
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Files required for setup
&lt;/h2&gt;

&lt;p&gt;Create a folder in your working directory.&lt;/p&gt;

&lt;p&gt;Add the files given below in the directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.php&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a basic PHP file which only prints a text on the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello - This is my first docker application"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dockerfile&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM php:7.2-apache
COPY index.php /var/www/html/index.php
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The base image php:7.2-apache is used. The base image is pulled from dockerhub.&lt;/li&gt;
&lt;li&gt;The file index.php is copied to /var/www/html/ in the image.&lt;/li&gt;
&lt;li&gt;The port 80 is exposed for apache.&lt;/li&gt;
&lt;li&gt;Apache is started inside the container.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Docker Commands
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Build an image using docker build command. We build the image with the name phpdemo and tag as v1.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t phpdemo:v1 .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run the image in a container using docker run command. We run one container from the image phpdemo:v1. Notice the -p tag. It is used to publish the host port 9090 to the container port 80. In short, if any request will come on port 9090, it will redirect that request to our container in port 80.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p9090:80 phpdemo:v1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open your browser and go to &lt;a href="http://localhost:9090/index.php"&gt;http://localhost:9090/index.php&lt;/a&gt;
You should see the output from the PHP file.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article, we discussed how to dockerize a basic PHP application. You can also read more articles on &lt;a href="http://concatly.com/topics/php/"&gt;PHP on Concatly&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>php</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
