Docker Deployment in Crowd+

Amrisandha Prasetyo
6 min readMay 25, 2021

What are containers and virtual machines?

Containers and VMs both isolate an application and its dependencies into a self-contained unit that can be run anywhere. However, they differ in the way they are architected.

A virtual machine (VM) is an emulation of a real computer that executes programs like a real computer. They run on top of a physical machine using hardware called the hypervisor.

A container provides operating-system-level virtualization by abstracting the “user space”. Hence, containers share the host system’s kernel with other containers. This architecture causes containers to be more light weight than virtual machines.

The difference between VMs and containers

About Docker

Docker is a tool based on Linux containers. It is designed to make application creation, deployment, and running easier by utilizing containers. By utilizing containers, developers can package up an application with all of the parts it needs, such as libraries and other dependencies into one package. Docker separate the application code from infrastructure requirements and needs.

By using Docker, developers can concentrate on the actual code development without worrying about the system the code will run on. Furthermore, devOps can focus on ensuring the right programs are installed in the Docker container and reduce the complexity of how systems are used and maintained.

The Benefits of Docker

No need to worry about dependencies

With Docker, there is no need to install 3rd-party apps like PostgreSQL on the system, you can run it in containers. Also, docker gives developers the ability to run different versions of same application simultaneously. Therefore, to avoid the complexity of keeping two different versions of the same app on one host OS, Docker containers could be a perfect solution, where it provides isolated environments for applications and 3rd-parties.

Application encapsulation

With Docker, developers can deliver the application in one piece. Docker provides a unified image format to distribute applications across different host systems and cloud services. Therefore, developers can deliver applications in one piece with all the required dependencies (included in an image) ready to run.

Consistent behavior

Docker reduces the probability of error caused by different versions of operating systems or system dependencies. This is due to the fact that the application will your application will use the same base Docker image with the same OS version and the required dependencies.

Easy and clear monitoring

Docker provides a unified way to documenting log files from all running containers. Therefore, developers do not longer need to remember all the specific paths of where the application and its dependencies store log files and write custom hooks to handle this.

High scalability

By design, Docker emphasizes to developers to follow its core principles, such as configuration over environment variables, communication over TCP/UDP ports, etc. With these principles in mind, the application can be more able to scale.

Fundamental Docker Components

Docker Engine

The docker engine is the layer where Docker runs. It’s a lightweight runtime and tooling that manages containers, images, builds, and more. It runs natively on Linux systems and is made up of:

Docker Client

The Docker Client is what you, as the end-user of Docker, communicate with, which is the interface of Docker. Docker Client then communicates users’ instructions to the Docker Daemon.

Docker Daemon

The Docker daemon is what actually executes commands sent to the Docker Client: building, running, and distributing containers. The Docker Daemon runs on the host machine.

Dockerfile

The Dockerfile is where you write the instructions to build a Docker image. Once the Dockerfile is set up, you can use the docker build command to build an image from it.

Docker Image

Images are read-only templates that you build from a set of instructions written in your Dockerfile. Images define how the packaged application and its dependencies will be and what processes are needed to run when it’s launched. The Docker image is built using a Dockerfile.

Docker Containers

A Docker container wraps the application’s software and everything the application needs to run. Docker containers are built off of Docker images. Since images are read-only, Docker adds a read-write file system over the read-only file system of the image to create a container. Once the container is successfully created, you can then run it in any environment without having to make changes.

Docker Commands

Here are some useful commands to use with Docker

Developing with Docker Containers:

  • docker create [image] Create a new container from a particular image.
  • docker login Log into the Docker Hub repository.
  • docker pull [image] Pull an image from the Docker Hub repository.
  • docker push [username/image] Push an image to the Docker Hub repository.
  • docker search [term] Search the Docker Hub repository for a particular term.
  • docker tag [source] [target] Create a target tag or alias that refers to a source image.

Running Docker Containers

  • docker start [container] Start a particular container.
  • docker stop [container] Stop a particular container.
  • docker exec -ti [container] [command] Run a shell command inside a particular container.
  • docker run -ti — image [image] [container] [command] Create and start a container at the same time, and then run a command inside it.
  • docker run -ti — rm — image [image] [container] [command] Create and start a container at the same time, run a command inside it, and then remove the container after executing the command.
  • docker pause [container] Pause all processes running within a particular container.

Using Docker Utilities:

  • docker history [image] Display the history of a particular image.
  • docker images List all of the images that are currently stored on the system.
  • docker inspect [object] Display low-level information about a particular Docker object.
  • docker ps List all of the containers that are currently running.
  • docker version Display the version of Docker that is currently installed on the system.

Cleaning Up Your Docker Environment:

  • docker kill [container] Kill a particular container.
  • docker kill $(docker ps -q) Kill all containers that are currently running.
  • docker rm [container] Delete a particular container that is not currently running.
  • docker rm $(docker ps -a -q) Delete all containers that are not currently running.

How we used Docker in Crowd+

Deployment Made Easier

During the development of Crowd+, we mainly used Docker for deployment in Heroku. This has helped us control the environment of the deployment process much easier, due to the fact that the application can be built anywhere and be released to the deployment platform.

Shared Configuration Among all Developers

We also felt the benefit of using Docker where the configuration of all stacks, one of them, including PostgresSQL, would be much the same among all of the developers. OS independence has also helped all developers in the team not further worry whether or not the application can be built and run.

Consistent Results

Last but not least, Docker has helped significantly where all of us, working in different areas of Indonesia with different types of computers, can expect the same results when building and running the application. With this in mind, we did not have to worry much about problems outside of the code development, which made us more focused on developing and delivering features of the application.

Conclusion

Docker offers very many benefits to developers in building, running, and shipping applications. It mainly helps developers with different computer technologies to be able to collaborate efficiently and effectively. As junior developers ourselves, we definitely have experienced the advantages Docker has to offer during our product development project. If you have the time and capability to implement Docker in your project, we really advise you to do so! Good luck!

--

--

Amrisandha Prasetyo
0 Followers

Computer science student at Universitas Indonesia | Aspiring product designer 🎨💻