Use Minishift To Test And Develop Your App Locally

Neil Smith
7 min readDec 12, 2020

What Is Minishift?

Minishift can be used to run and deploy apps locally on your own computer by using Docker. It can be a great way test out and develop your app locally before you deploy it in a production environment. Minishift is similar to Kubernetes, its a way of handling all your apps made using Docker.

In this tutorial I’m going to show you how to setup Minishift and use it to run a simple python app I’ve included here that responds with the message “Connected to the python server!” whenever you interact with it.

What Is Docker?

Using Docker you can create applications that run on any device. You create a Dockerfile which contains all the settings for your app and which files to run and any other files it may need. From the Dockerfile you can create a docker image, which is like a class, a blueprint for your app. From the image you can then create an instance of your app, as many as you want. As long as a device can run Docker it can run your app.

Setup Minishift

To get Minishift to work you have to run it within a virtual machine, which is basically just another computer and Operating System that takes up a separate part of your computer’s storage to your normal computer. You can have 2 or more operating systems installed on the same computer. You can setup a virtual machine on most computers, but you have to deal with something called a hypervisor to enable it. Instead of dealing with the hypervisor, we can use some software called VirtualBox instead, which also allows us to setup a virtual machine on your computer.

First go to the VirtualBox downloads page and download and install VirtualBox.

Install Minishift On Mac

On Mac you can install Minishift using Homebrew by typing the following into your command terminal. If you haven’t got Homebrew go to their website https://brew.sh/ and install it.

brew cask install minishift

Install Minishift On Windows

Next we can download and install Minishift from here. You can extract the files to anywhere you want. Then we will need to add the path to the minishift.exe file to the PATH environment variables, which registers it with your computer and allows other programs to easily find and use it and allows us to run it from any directory in the terminal. Normally this happens automatically when you install a program but for some programs it doesn’t.

Search for ‘Environment Variables’.

Click on the ‘Path’ Environment Variable and click ‘Edit…’

Click ‘New’ and add the path to the folder containing the minishift.exe file.

Run Minishift

Now use VirtualBox to run your Minishift VM (Virtual Machine). This will start Minishift and also install Docker.

minishift start --vm-driver=virtualbox

If you open up VirtualBox you can now see it has created a virtual machine for minishift to run in.

Once its done it should show a URL, you can copy and paste this URL into your browser to open up Minishift in your browser which you can use to see all your running apps.

Install Openshift CLI On Mac

Now back in the terminal, use homebrew to install the OpenShift command-line interface which allows us to quickly run and stop any apps we create from the command terminal instead of using the UI.

brew install openshift-cli 

Install Openshift CLI On Windows

Next we need to install the OpenShift Command Line Interface which allows us to quickly run and stop any apps we create from the command terminal instead of using the UI.

Download it from here and extract its contents to wherever you want. Add the path to the folder containing this file to the Path environment variable like before when installing minishift.

You can check the openshift-cli is installed by typing

oc version

Setup Docker

We next need to tell our command terminal to use the Docker installed within the Virtual Machine we created instead of the Docker that you might already have installed on your computer. To do that we can type the following into the terminal

eval $(minishift docker-env)

To save a copy of our app locally we will need to login to the Minishift image registry with the username developer. You can do that using

docker login -u developer -p $(oc whoami -t) $(minishift openshift registry)

Build And Deploy Your App

To build an image of an app, you’ll need a Dockerfile. In this example, I’ll use a Dockerfile with a simple python script that listens for connections and responds with the message “Connected to the python server!”. You can get this Dockerfile and python script at https://github.com/s3nt1n3lz21/SimplePythonServerApp/tree/master. Place both of these files in a folder and then navigate to this folder in your terminal. I’ve placed mine in a folder named minishiftExample in my Documents folder. To navigate to it in the terminal I can just type

cd ~/Documents/minishiftExample

Then we can build the image of the app, giving it the name pythonserverapp.

docker build -t pythonserverapp .

You can check that the image was created by typing

docker images

You should also see some OpenShift images for the different parts of OpenShift. This is because OpenShift itself was installed using containers on the VM. There should be an image for a pod and an image for a container and so on. Now we’ll use the OpenShift command line interface to build a new project and upload this image. Create a new project, giving it the name pythonserverproject.

oc new-project pythonserverproject

We now need to create an imagestream from the image. An imagestream is a way of collecting similar images together. You can have multiple images part of an imagestream. Usually they are used to hold the different versions of the same image. Here we will just have our single image in the imagestream. We add our image to an imagestream by tagging it.

docker tag pythonserverapp $(minishift openshift registry)/pythonserverproject/pythonserverapp

Now push the image up to the minishift image registry

docker push $(minishift openshift registry)/pythonserverproject/pythonserverapp

Create an app in this project using the image from this imagestream.

oc new-app --image-stream=pythonserverapp --name=pythonserverapp

Your app should now be created and running on the OpenShift cluster, but we can’t access it from outside of the cluster.

Test Your App

We can quickly test the app is working for now by entering the cluster by using SSH to enter the VM environment and access the VM terminal. First we list the services of our app

oc get svc

Note down the ClusterIP and the Port number. The ClusterIP should be something like 172.30.107.237 and the Port number should be something like 3306.
Now enter the terminal of the VM using SSH

minishift ssh

Now use cURL to connect to the ClusterIP and port number of the service and send a request for data. It should be something like.

curl 172.30.107.237:3306

You should get a message back saying “Connected to the python server!”. You can exit the VM environment by typing

exit

Expose Your App

To be able to access the app from outside the VM cluster, we first need to expose the service.

oc expose service pythonserverapp

We now need to change the type of the service from ClusterIP to LoadBalancer, by default its set to ClusterIP. To do this, go back to the console in the browser. Login with the username developer with any password, it doesn’t matter. Click on the project pythonserverproject from the list of projects on the right. On the left, select Applications, Services and click on the service pythonserverapp. Go to the top right and click on Actions, Edit YAML and change the spec.type field from ClusterIP to LoadBalancer. Back on the service page there should now be a section called Traffic. Note down the value of Node Port. Back in the console you should now be able to send a request to the service using the minishift master IP from earlier, the IP the webconsole UI uses, and this Node Port. This should be something like

curl 192.168.99.103:31664

You should get a message saying “Connected to the python server!”. And there you have it, you’ve successfully built an image and got the app running on the Minishift cluster. If you want to edit your app and redeploy it, all you need to do is rebuild the image, tag it and push it up again.

--

--