Deploying laravel application to Digital ocean kubernetes - Part 1

Coding Monk
Apr 5, 2020 · 3 min read

Building Docker image for PHP Application

This is a first post of this tutorial series, in this tutorial we will only learn how you can wrap your application into docker image, which we will be needing when we learn about deploying kubernetes application.

So let’s just revise what is kubernetes?

Kubernetes is most popular container orchestration framework. You might have heard that kubernetes makes scaling user easy and manageable. Yes it’s true. To deploy kubernetes application we need an application docker image, image can be hosted on google cloud or docker hub. Docker hub provides 1 private image for free and unlimited public images.

  1. Installing docker.

First step is to install docker on machine, i am not going into how to install docker on you machine, you can check this Youtube Tutorial.

2. Creating Dockerfile

As you can see first line is an base image which we want to extend, we will be using php-7.3.3-apache-stretch image, it will contain php and apache server.

Third line we are changing our work directory and copying index.php from current directory to index.php into /var/www/html of image.

Our index.php file contains simple Hello there html.

If you want to install any extension to image, for eg. curl. you have to follow docker syntax, you will get all the basic php extensions from here.

Now go to directory where you docker file and index.php file is located, we are assuming both files are in same directory. To build docker image above command is used.

docker build docker -t {tag_for_your_image}

As you can see our index.php file is copied to image and image is build successfully.

Above command will run image we have built locally, container name we have specified using name argument.

It is running on 127.17.0.2 IP address, if go to that address we will be able to see our index.php

Now it’s time to push this image to docker hub. You will have to login to docker hub from you cli to push image to docker hub, just perform.

docker login and enter credentials.

Use docker image push {name_of_your_local_docker_image} command to push image to docker hub after login.

There are no repository right now.

Image is pushed to docker hub.

That’s all your php image is ready to deploy on docker.

Here is video tutorial if you want to follow along.

Thank you so much.

Coding Monk

We are here for quick tutorials, it may be server…

Coding Monk

We are here for quick tutorials, it may be server administration, server setup, dev ops, simple programming tips, simple hacks for server and many other things.

Coding Monk

Written by

We are here for quick tutorials, it may be server administration, server setup, dev ops, simple programming tips, simple hacks for server and many other things.

Coding Monk

We are here for quick tutorials, it may be server administration, server setup, dev ops, simple programming tips, simple hacks for server and many other things.