@matwolbec tutorials
Back to page 7
Custom application
We will create a simple docker image to customize the HTML and see it running
Requirements
- Docker https://docs.docker.com/engine/install/
- Docker Hub Account https://hub.docker.com/
Dockerfile
Let’s create a Dockerfile and push it to Dockerhub.
mkdir docker
cd docker
touch Dockerfile
Open the file and add:
FROM php:7.4-apache
COPY . /var/www/html/
Create a index.php file. We want to PHP print the hostname, so we will know what host we are getting to:
touch index.php
Add the content:
<?php
echo gethostname();
?>
Building the docker image
Now you should have your dockerhub account. Let’s build. Don’t forget to substitute the <your-dockerhub-name> by your account. For example, mine is matwolbec.
docker build -t <your-dockerhub-name>/php-gethostname:v1 -f Dockerfile .
Before we can push it, let’s create the repository on DockerHub: https://hub.docker.com/repository/create.
Name it php-gethostname and leave the visibility as Public.
Login on your docker-cli:
docker login
We can now push it to dockerhub:
docker push matwolbec/php-gethostname:v1
We should tag the version as the latest available:
docker tag matwolbec/php-gethostname:v1 matwolbec/php-gethostname:latest
docker push matwolbec/php-gethostname:latest
cd ..
Deploying our image to our Kubeernetes cluster
Open the deployment.yaml and change:
image: httpd:latest
To:
image: matwolbec/php-gethostname:latest
And apply:
kubectl apply -f deployment.yaml
You can watch the magic happening with:
kubectl get pods
Destroying
Don’t forget to destroy your resources to avoid charges.
Run:
kubectl delete -f deployment.yaml
terraform destroy
Next steps
Go to Ingress Controller.