Blesta docker部署

Blesta docker部署,定制打包Blesta镜像,oneman第一步

环境与前提

已安装 Docker Compose

主机目录结构:

1
2
3
4
5
/root/blesta-storage/db_data
/root/blesta-storage/npm_data
/root/blesta-storage/npm_letsencrypt
/root/blesta-storage/blesta_data
/root/blesta-storage/blesta.dockerfile

Docker Compose 配置 (docker-compose.yml)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
version: '3.8'
services:
  mariadb:
    image: mariadb:10.6
    container_name: blesta-mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password      # TODO: 替换为安全密码
      MYSQL_DATABASE: blesta
      MYSQL_USER: blesta
      MYSQL_PASSWORD: password           # TODO: 替换为安全密码
    volumes:
      - /root/blesta-storage/db_data:/var/lib/mysql
    networks:
      - blestanetwork

  npm:
    image: jc21/nginx-proxy-manager:latest
    container_name: blesta-npm
    restart: always
    ports:
      - "80:80"
      - "443:443"
      - "8080:81"
    volumes:
      - /root/blesta-storage/npm_data:/data
      - /root/blesta-storage/npm_letsencrypt:/etc/letsencrypt
    networks:
      - blestanetwork

  blesta:
    build:
      context: /root/blesta-storage
      dockerfile: blesta.dockerfile
      network: host     # 这里需要为host才能执行build里的apt install
    container_name: blesta
    restart: always
    environment:
      DB_HOST: mariadb
      DB_PORT: 3306
      DB_NAME: blesta
      DB_USER: blesta
      DB_PASS: password
    volumes:
      - /root/blesta-storage/blesta_data:/var/www/html
    depends_on:
      - mariadb
    networks:
      - blestanetwork

networks:
  blestanetwork:
    driver: bridge

Blesta Dockerfile (blesta.dockerfile)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
FROM php:8.1-apache

# 安装系统依赖和 PHP 扩展编译依赖
RUN apt-get update && apt-get install -y \
    wget unzip rsync \
    libpng-dev libjpeg-dev libfreetype6-dev pkg-config \
    libgmp-dev \
    libc-client-dev libkrb5-dev libssl-dev \
    libxml2-dev autoconf gcc make pkg-config \
  && rm -rf /var/lib/apt/lists/*

# 配置并安装 PHP 扩展
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
  && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
  && docker-php-ext-install \
       gd gmp imap soap mysqli pdo pdo_mysql \
  && pecl install mailparse \
  && docker-php-ext-enable mailparse

# 安装 ionCube Loader for PHP 8.1
RUN wget -qO /tmp/ioncube.tar.gz \
      https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz \
  && tar zxvf /tmp/ioncube.tar.gz -C /tmp \
  && EXT_DIR=$(php -r 'echo ini_get("extension_dir");') \
  && mv /tmp/ioncube/ioncube_loader_lin_8.1.so "$EXT_DIR" \
  && echo "zend_extension=ioncube_loader_lin_8.1.so" \
       > /usr/local/etc/php/conf.d/00-ioncube.ini \
  && rm -rf /tmp/ioncube*

# 下载并解压 Blesta 5.11.3 源码
RUN wget --no-check-certificate -O /tmp/blesta.zip \
      "https://account.blesta.com/client/plugin/download_manager/client_main/download/227/blesta-5.11.3.zip" \
  && mkdir -p /tmp/blesta_src /usr/src/blesta \
  && unzip /tmp/blesta.zip -d /tmp/blesta_src \
  && rm /tmp/blesta.zip \
  && for sub in /tmp/blesta_src/*; do \
       mv "$sub"/* /usr/src/blesta/ 2>/dev/null || true; \
     done \
  && rm -rf /tmp/blesta_src \
  && chown -R www-data:www-data /usr/src/blesta

# 启用 Apache 重写模块
RUN a2enmod rewrite

# 暴露端口
EXPOSE 80

# 首次启动时复制源码并启动 Apache
ENTRYPOINT ["sh","-c","\
  if [ ! -f /var/www/html/index.php ]; then \
    echo '首次部署:拷贝 Blesta 源码…'; \
    cp -a /usr/src/blesta/. /var/www/html; \
    chown -R www-data:www-data /var/www/html; \
  fi; \
  exec apache2-foreground\"]

部署流程与命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cd /root/blesta-storage
docker compose up -d --build

# 查看运行状态
docker compose ps

# 查看日志
docker compose logs -f blesta

# 停止与重启
docker compose stop
docker compose start
# 或者一条命令重启
docker compose restart

# 更新 Blesta 版本(可能存在与安装环境版本兼容问题)
# 1. 下载新版本 ZIP 并替换 /usr/src/blesta 下的源码
# 2. 重建并重启容器
docker compose up -d --build blesta
使用 Hugo 构建
主题 StackJimmy 设计