本文构建镜像基于兰空图床最新稳定版 v2.0.4 https://github.com/lsky-org/lsky-pro/releases/tag/2.0.4

# 准备路径并进入  
$ mkdir -p /home/dk/temp/docker/lskypro && cd /home/dk/temp/docker/lskypro

# 下载 2.0.4 稳定版的压缩包
$ wget https://github.com/lsky-org/lsky-pro/releases/download/2.0.4/lsky-pro-2.0.4.zip

# 解压之
$ unzip lsky-pro-2.0.4.zip

# 把原始压缩包删除或挪走
$ mv lsky-pro-2.0.4.zip ../

# 删除部分文件,以减小镜像体积 为了不影响 composer install 把 composer.lock 文件删掉
$ rm -rf LICENSE README.md composer.lock .gitignore

# 设置一下权限 755 (使用 . 包含隐藏文件,使用 ./* 不包含隐藏文件)
$ chmod -R 755 .

安装 composer.json 中定义的依赖

$ composer install

创建以下三个文件

  • 000-default.conf
  • Dockerfile
  • entrypoint.sh

000-default.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
        # ServerName demo.site 

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Dockerfile

FROM php:8.1-apache
MAINTAINER hellodk <[email protected]>
RUN a2enmod rewrite

# 使用 ustc 镜像加速
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \
    apt-get clean
# 安装相关拓展
RUN apt update && apt install imagemagick libmagickwand-dev -y \
    && pecl install imagick \
    && docker-php-ext-install bcmath \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-enable imagick 
RUN { \
    echo 'post_max_size = 100M;';\
    echo 'upload_max_filesize = 100M;';\
    echo 'max_execution_time = 600S;';\
    } > /usr/local/etc/php/conf.d/docker-php-upload.ini; 
RUN { \
    echo 'opcache.enable=1'; \
    echo 'opcache.interned_strings_buffer=8'; \
    echo 'opcache.max_accelerated_files=10000'; \
    echo 'opcache.memory_consumption=128'; \
    echo 'opcache.save_comments=1'; \
    echo 'opcache.revalidate_freq=1'; \
    } > /usr/local/etc/php/conf.d/opcache-recommended.ini; \
    \
    echo 'apc.enable_cli=1' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini; \
    \
    echo 'memory_limit=512M' > /usr/local/etc/php/conf.d/memory-limit.ini; \
    \
    mkdir -p /var/www/data; \
    chown -R www-data:root /var/www; \
    chmod -R g=u /var/www

COPY ./ /var/www/lsky/
COPY ./000-default.conf /etc/apache2/sites-enabled/
COPY entrypoint.sh /
WORKDIR /var/www/html
VOLUME /var/www/html
EXPOSE 80
RUN chmod a+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["apachectl","-D","FOREGROUND"]

entrypoint.sh

#!/bin/bash
set -eu

if [ ! -e '/var/www/html/public/index.php' ]; then
    cp -a /var/www/lsky/* /var/www/html/
    cp -a /var/www/lsky/.env.example /var/www/html
fi
    chown -R www-data /var/www/html
    chgrp -R www-data /var/www/html
    chmod -R 755 /var/www/html/

exec "$@"

使用 docker build 构建镜像

$ sudo docker build -f Dockerfile -t lsky-pro:2.0.4 .

构建成功后提示

Successfully built 67335026bf05
Successfully tagged lsky-pro:2.0.4

经测试,该镜像可用。由于 docker hub 中 MySQL 官方提供的 MySQL 5.7 版本没有支持 arm64 架构的镜像。于是寻找到了替代品 ibex/debian-mysql-server-5.7:latest

$ sudo docker pull ibex/debian-mysql-server-5.7:latest

创建一个 mysql5.7 容器

$ sudo docker run -d -p 3306:3306 --name mysql5.7 --restart=unless-stopped -e MYSQL_ROOT_PASSWORD=123456 ibex/debian-mysql-server-5.7

查看该容器的 IP,是 192.168.50.6 本文容器都使用的 bridge 网络。

创建一个 lsky-pro 容器

$ sudo docker run -d --name=lsky-pro0501-1 -v /mnt/reamaxdisk/dockerdata/persistentdata/lsky-pro-data-6:/var/www/html -p 7791:80 lsky-pro:2.0.4

浏览器访问 http://10.10.10.4:7791 成功进入安装界面,现在创建数据库中 lsky-pro 专用的用户名密码和数据库

# 进入 mysql5.7 容器
$ sudo docker exec -it mysql5.7 bash

# mysql -uroot -p123456

# 创建用户,密码随意
mysql> create user 'lskypro'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'lskypro'@'%' with grant option;
mysql> flush privileges;

# 创建数据库
mysql> create database lskypro;

最后通过 http://10.10.10.4:7791 填入相关信息即可成功安装。端口是 3306,数据库 IP 是 192.168.50.6


本文构建的兰空图床 V2 的 docker 镜像,也已支持 AMD64 架构,托管在 docker hub,地址是 https://hub.docker.com/r/dko0/lsky-pro 详细说明请见下一篇文章,我将介绍是如何通过 docker buildx 同时构建多架构镜像的。