Use Docker Depoly Website

Tech save the world!

Introduction

This article will primarily introduce the reasons for choosing docker and docker-compose as the foundation for setting up this website’s environment and provide a detailed method for doing so. It provides some insights for beginners in website development.

Background

Initially, the motivation was to address environmental issues. From using the “lnmp.org” one-click setup I learned from the wild five years ago (which seems to have been acquired?), to using the Baota panel for one-click deployment of environments. It seems (not really) to be a good choice. After all, they are pre-built by others, right? However, the space for customization and personalization is too small. The functions you use are already highly integrated, modular, one-click, and user-friendly. Moreover, their products are mostly aimed at serving government and enterprise websites, aiming for low maintenance. This is quite the opposite of the “technological radicalness” and “high customizability” goals of a personal blog. So, do it yourself to make a living!

Goals

Quickly build the runtime or development environment (based on services) required for common development languages and be able to “unify management” of the status of each service, “simplify” service configuration, “simplify” data backup processes, “facilitate” local debugging and “cross-platform” migration and deployment.

Services needed:

  • Nginx/Caddy - Web server
  • PHP (Only FPM) - The best language in the world (believe it)
  • MySQL - Database
  • Redis - Cache
  • Gitea - Code hosting
  • Portainer - Docker management tool
  • phpMyAdmin - Database management tool

Technology Choices

Why use docker and docker-compose?

Before using docker, let’s introduce the concepts of docker and docker-compose.

What is Docker?

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can also use Compose, and you can also use Compose to define a multi-container application. To define the services, you can use a single command to start or dismantle all the content.

– From Docker Official Documentation

What is Docker-compose?

Docker-Compose is a tool that helps you define and share multi-container applications. With Compose, you can create a YAML file to define services, and use a single command to start or dismantle all content.

– From Docker Official Documentation

Installing Docker

Detailed installation instructions can be found in the official documentation.

Tips: Due to the network environment in China, if you encounter slow downloads, you can install Docker using a domestic mirror source, for example, visit Beijing Foreign Studies University’s mirror source.

Quick installation: Before installing, make sure you have uninstalled old versions of Docker. Assuming the operating system is Ubuntu/Debian/CentOS.

1
2
3
4
5
6
# Optional: Set mirror source
export DOWNLOAD_URL="https://mirrors.bfsu.edu.cn/docker-ce"
# If you use curl
curl -fsSL https://get.docker.com/ | sudo -E sh
# If you use wget
wget -O- https://get.docker.com/ | sudo -E sh

docker-compose的安装

参考Docker-compose安装-官方文档

快速安装:使用包管理器。

1
2
3
4
# Ubuntu/Debian
sudo apt install docker-compose
# CentOS
sudo yum install docker-compose

使用docker-compose构建基础环境

这里开始介绍如何使用docker-compose构建基础环境。

代码拉取

1
git clone https://git.cloudorz.com/mt/server.git --depth=1

服务配置

这里需要配置一些服务的配置文件。这里以Caddy为例。

启动服务

按需启动服务。这里以启动Caddy+PHP+MySQL+phpMyAdmin为例。

1
docker-compose up -d caddy php-fpm-82 mysql phpmyadmin

随后查看服务状态

1
docker-compose ps
辽ICP备18009435号-1
Built with Hugo
Theme Stack designed by Jimmy