Docker Php Application Example
We can run php application using docker. In the following steps, we are creating and running php application.
Create a directory
Create a directory to organize files by using following command.
$ mkdir php-docker-app
See, screen shot of the above command.
Create a Php File
// index.php
echo ?Hello, Php?;
Create a DockerFile
// Dockefile
FROM php:7.0-apache
COPY . /var/www/php
After that our project has two files like the below screen-shot.
Create Docker Image
$ docker build -t php-app .
In the below screen-shot, we are creating docker image.
Now look for the available images in the docker container.
The above screen-shot shows that the created image
php-app
is available.
Run the Docker image
Now run the docker image. The following command is used to run docker images.
$ docker run php-app
We 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: