Docker + PHP Application Example


We can run php application using docker. In the following steps, we are creating and running php application.
  1. Create a directory
  2. Create a directory to organize files by using following command.
    1. mkdir php-docker-app  
    See, screen shot of the above command.
    Docker Php application 1

  3. Create a Php File
  4. index.php
    1. <?php  
    2.     echo ?Hello, Php?;  
    3. ?>  

  5. Create a DockerFile
  6. Dockefile
    1. FROM php:7.0-apache  
    2. COPY . /var/www/php  
    After that our project has two files like the below screen-shot.
    Docker Php application 2

  7. Create Docker Image
    1. $ docker build -t php-app .  
    In the below screen-shot, we are creating docker image.
    Docker Php application 3Now look for the available images in the docker container.
    Docker Php application 4The above screen-shot shows that the created image php-app is available.

  8. Run the Docker image
  9. Now run the docker image. The following command is used to run docker images.
    1. $ docker run php-app  
    Docker Php application 5We can see that our docker image is running and output is shown to the browser. This image is running on the 172.17.0.2 ip.

    Output:
    Docker Php application 6


Reference:


Post a Comment

Mới hơn Cũ hơn