Empowering App Development for Developers — Docker
Let’s say you wanna deploy your app to a host — or other developers wanna try the app in their computer, but you have to make sure your app can run smoothly on a different environment. Before cloud computing is not that common, you can use BASH script to install your app dependencies in host. Now, there is many cloud computing service for everyone and faster/ easier deployment is key to make your app more available and reachable.
What is Docker?
Docker is an open platform that package your application and run it on a semi-isolated environment. Docker called this a container. Container is a lightweight “virtual machine” that runs an application with necessary dependencies, means that each container have its own Operating System (OS) for its application. The reason it is called lightweight because if there’s two containers with the same OS version, then these two containers can use the same OS kernel and, usually, the binaries and libraries. Containers also easily shared, so other developers can have the same standardized environment for the application.
Because container is easily shared, and the configs is same — other developers can work on a standardized environment. Also, deployment will be consistent on all host.
Container also have much faster start time than Hypervisor-based Virtual Machines, so deployment will be faster in CI/CD workflow.
Docker can run on any supported OS, and because of its lightweight — ness, one host can run multiple containers or even more than Hypervisor-based Virtual Machines.
How to Use Docker?
First, let’s find out docker components:
- Docker image, a component contains information about OS configuration, dependencies, and other mandatory things needed for the application can be run on a container
- Docker container, an OS that uses the docker image configuration
- Dockerfile, a list of commands to make a Docker image
- docker-compose, a file that “orchestrate” one or many necessary containers to run the app on single host
To make explanation easier, I’m gonna use our PPL Project back-end docker-compose file
From the file, we make 5 services to run our backend API service:
- rabbitmq, message queue service
- ms, meilisearch NoSQL service
- db, postgresSQL service
- web, main API service
- worker, worker for main API service
Then, I’m gonna explain some essential syntax to make docker-compose
- image, image that gonna be used for the container, you can explore more images in Docker Hub
- ports, ports that Docker gonna forward to the host
- build, tell Docker to use Dockerfile for that service
After that, you can use command
to run your own Docker Compose app — to stop the app, you can use
Or to make it easier, you can use Docker Desktop GUI for easier use
In Docker Desktop, you can start, stop, restart, or delete your container(s) with just a click of a button.
To learn more about docker-compose, you can learn in Get started with Docker Compose | Docker Documentation
Wait there’s more?
Docker is even more complex now with the introduction of multi host orchestrator like Docker Swarm and Kubernetes. Then, what’s the difference with Docker Compose then?
Docker Compose is used for configuring and starting multiple containers on the same host — so you don’t have to start each container separately. Docker swarm is a container orchestration tool that allows you to run and connect containers on multiple hosts.
The advantages of using Kubernetes then Docker Swarm, is that Kubernetes has an informative detailed dashboards to manage containers, but with slower deployment than Docker Swarm.
We don’t use these kind of tool on our PPL Project, because it’s overkill and unnecessary for our current project :)
Docker can make your deployment or sharing your development environment to other developers easier and faster, because Docker can standardized the app environment.
Docker is already evolving from a single container to many container in different host, also making it more harder to manage. That’s why orchestration tool like Docker Compose, Docker Swarm, or Kubernetes to the rescue to manage many containers.
That’s all I have for Docker, feel free to read my other articles!