Imagine you've spent your entire life developing a Vue.js web application on your powerful Windows PC, and when you deploy it to your centos7 server with confidence – oh no, nodejs can't handle your dependency tree! You have to waste your precious life on the tedious work of adjusting dependencies and testing, not to mention that this usually just makes things worse. Yes, docker can solve this problem once and for all!
1. What is Docker?
Docker is a Container that loads the dependencies and environment required for an application to run. Unlike virtual machines in the general sense, containers do not have their own operating system. Instead, they use the system kernel of the host machine directly. Each docker container is built and run step by step by the Docker Engine according to the build commands of the Image. These concepts will be explained in the following.
2. Docker Architecture
Docker uses a classic Client-Server (CS) architecture.

The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.
After accepting the commands input by the terminal, the client calls docker-demon through the API to process them, such as running, building, and pushing commands for images.
Registry is a storage and distribution repository for docker images, similar to GitHub. Images and related extensions and plugins can be easily pulled and pushed. Currently, the official docker repository is Docker Hub, and there are many third-party repositories available.
3. DockerFile
If you want to build your docker image, you must use a dockerfile to specify the build commands (this is like a makefile, as I described in another blog post). It will be run line by line and build an environment that includes the specified dependencies. A simple example is as follows, which comes from one of my previous timetable projects, developed by Vue + Express.js.
# Frontend build
FROM node:16 as frontend-build
WORKDIR /app
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ .
RUN npm run build
# Backend build
FROM node:16 as backend-build
WORKDIR /app
COPY backend/package*.json ./
RUN npm install
COPY backend/ .
# Set Nginx Server
FROM nginx:stable
COPY --from=frontend-build /app/dist /usr/share/nginx/html
COPY --from=backend-build /app /usr/share/nginx/backend
# Custom Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80 443
# Start Nginx server
CMD ["nginx", "-g", "daemon off;"]
4. Docker Compose
Docker-compose provides a way to configure Docker parameters in YAML/YML files, which is often used when deploying Docker applications that require multiple services at the same time, such as applications that depend on database systems. In practical applications, it can easily deploy several docker containers in a docker network, which solves various problems caused by this to a large extent. However, in this article, I don't want to go into too much detail about the application.
A typical docker-compose.yaml
file looks like this:
version: "3"
services:
navidrome:
image: deluan/navidrome:latest
ports:
- "4533:4533"
restart: unless-stopped
environment:
ND_ENABLETRANSCODINGCONFIG: "true"
ND_TRANSCODINGCACHESIZE: "0"
ND_SCANSCHEDULE: "1h"
ND_LOGLEVEL: "info"
ND_SESSIONTIMEOUT: "24h"
ND_BASEURL: ""
ND_LASTFM_APIKEY: "<Key>"
ND_LASTFM_SECRET: "<Key>"
ND_SPOTIFY_ID: "<Key>"
ND_SPOTIFY_SECRET: "<Key>"
volumes:
- "/root/navidrome/data:/data"
- "/root/miodrive/music:/music:ro"
5. Cluster Deployment
For the clustered deployment of docker containers, the mainstream tool is Kubernetes (k8s), developed by Google and open sourced.

Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
A Kubernetes cluster consists of a control plane plus a set of worker machines, called nodes, that run containerized applications. Every cluster needs at least one worker node in order to run Pods.
The worker node(s) host the Pods that are the components of the application workload. The control plane manages the worker nodes and the Pods in the cluster. In production environments, the control plane usually runs across multiple computers and a cluster usually runs multiple nodes, providing fault-tolerance and high availability.
The architecture and principles of k8s will be discussed in a later article.
Appendix
If you want to know the official explanation of various Docker objects (images, volumes, etc.), please refer to: Docker Docs
If you are looking for a useful docker and k8s visual management tool, then I recommend Portainer to you.
Reference
Docker. (n.d.). Docker overview. Docker Documentation. Available at: https://docs.docker.com/get-started/docker-overview/
Hashemi-Pour, C., Bigelow, S. J., & Courtemanche, M. (n.d.). Docker. TechTarget SearchITOperations. Available at: https://www.techtarget.com/searchitoperations/definition/Docker
SRETips. (n.d.). What is Kubernetes? SRETips. Available at: https://sretips.com.br/kubernetes/k8s-what-is-kubernetes/
Comments | NOTHING