Moby Dock: Getting Familiar with the Friendly Blue Whale

Naima Moertadho
PsychoTeam
Published in
4 min readApr 15, 2019

Upon reading the title and writer of this article, you might wonder: how does a Hustler end up also being the DevOps engineer? Well, the answer is because it’s a mandatory competency to have in this course (hehe hi lecturers!), and the fact that at the beginning of the course none of my teammates’ operating systems could run Docker.

Yes! I was the lucky first to get acquainted with Docker, and how to use it.

Moby Dock: the friendly neighborhood Blue Whale

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

We implement Docker in our project in conjunction with Portainer. How? I will explain it in the section below.

Docker Setup

So, in a nutshell our project consists of two applications: the Client app (Android-based) and the Admin app (Django-based). We are also using API that we create From those two applications, we create two types of Docker image, the frontend image which serves a download link for our Android application, and the backend image which is where we deploy our Django application. Below, I will detail the necessary files to build our Docker image.

requirements.txt & build.gradle

These files contain the dependencies necessary to test and run the application. Requirements.txt is used to define the packages that need to be installed for the Django app, while build.gradle defines the necessary packages for the Android app.

Dockerfile

To build an image, Docker will try to find a Dockerfile in order to know what is needed in the image. In our project, we are using three Dockerfiles. One to build the backend image, and two to build the frontend image. Why two different kinds for frontend? Well, because we use a different type of APK for the production environment.

This Docker image will use a python:3.5-slim image. We first install the requirements needed, and then we set the command so that start.sh will be run when the Docker image is run.

For the frontend Dockerfiles, we essentially copy the APK that is already created, and serve a static link to download it using nginx:alpine.

start.sh

This file tells Django to make migrations and migrate first before deploying the app using Gunicorn. Here, we also determine the port that will be used to deploy our Docker image.

Manual Deployment

If for some reason automated deployment is unavailable (such as in the event of Gitlab being down, or our images mysteriously disappearing from the registry), we can manually build the image and push it to the registry using our local host. This is the command you need to run to build the project image and push it to the Docker registry.

Automated Deployment

To automatically deploy the project every time the Gitlab pipeline runs, we need to configure the .gitlab-ci.yml file.

The snippet above will run only on the staging branch (as defined by only: -staging). In a nutshell, the script will build the docker image using the designated Dockerfile, and push it to registry.docker.ppl.cs.ui.ac.id.

Portainer

After we push the image to the registry, we need to actually deploy it! How? Using Portainer! What is a Portainer? Well, it’s a GUI-based docker image manager. How do we use it? Worry not! I’ll explain. Because several of our containers and docker images mysteriously disappeared, I will sadly explain only using the docker image that is left.

1. Pull image from registry

In the images menu, pull the docker image from the registry.

How to pull development image from registry

2. Create container

After you’ve pulled the image, it is time to create a container in which the image will be deployed. Set the container part according to the port exposed in Dockerfile (80), and set the host according to your heart’s fancy.

The display for creating containers

After all the fields are filled, all you have to do is press the button deploy the container.

Testing the container

Open the port that you deployed the container on. If the download link is there, then the application has been successfully deployed.

The container is deployed! Rejoice!

Thus concludes the journey that is deploying our application using Docker with the help of Portainer. I’ll admit there were numerous moments where we flailed in panic meeting errors we’ve never even heard of. But I like to think we did pretty well for a bunch of kids who had no idea what Docker even was.

--

--