Ship a Full Web-Application With Docker¶
In this lecture you are going to create a full web-application that you can ship with Docker to anywhere in the world.
Ship your Web-Application using Apache and PHP as Docker container with a Dockerfile¶
Let's create a Docker image and run this image as container with an Apache with PHP pre-installed. Then serve our index.php from the previous example.
Change the Dockerfile to:
FROM php:7.2-apache
COPY index.php /var/www/html
Then run the following commands:
docker build -t myphpapp .
- This will build an image
myphpapp:latest
- Will copy the index.php from the host inside the container in the directory /var/www/html
- Will package everything
docker run --name myphp-apache -p 8080:80 myphpapp
- Will run the image
myphpapp
- Open the apache inside the image
- Bind port 8080 on the host to port 80 on the guest
- Will give the container the name “myphp-apache”
- Should bring up the "hello world" from the index.php
Now change the index.php to:
<?php
echo "hello universe \n\n";
- Simply changing the index.php on the host should not change it on the guest – it's baked into the image
- If you want a live version you need to volume-mount it into the container (
-v ${PWD}/index.php:/var/www/html/index.php
) - Now revert back the index.php!
To stop everything hit ctrl+c
Cleanup:
docker rm -f myphp-apache
- To remove the container
docker rmi myphpapp
- To remove the image for now