RUN sed -i 's/deb.debian.org\|security.debian.org/mirrors.tuna.tsing.edu.cn/g' /etc/apt/sources.list && \ apt update && apt install -y git ENV THINKPHP_VERSION=5.0.22
RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load \ && sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \ && sed -i 's#/var/www/html#/var/www/html/tp5/public#g' /etc/apache2/sites-enabled/000-default.conf RUN git clone --depth 1 -b v$THINKPHP_VERSION https://gitee.com/liu21st/thinkphp.git ./tp5 && \ git clone --depth 1 -b v$THINKPHP_VERSION https://gitee.com/liu21st/framework.git ./tp5/thinkphp
ADD . /var/www/html/
主要修改的地方有:
第 3-4 行:将官方 apt 源修改为清华镜像源,并下载 git 工具
第 10 行:修改DocumentRoot指向的public 目录位置
第 12-13 行:拉取 ThinkPHP 5.0.22 的 public 等文件和 thinkphp 框架
创建并运行 ThinkPHP 容器
基于 Dockerfile 文件,可以构建如下的 shell 脚本文件 run-tp5.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
THINKPHP_VERSION=5.0.22
if [[ -n $(docker image ls | grep -v local/thinkphp:v${THINKPHP_VERSION}) ]]; then echo "create local image 'local/thinkphp:v${THINKPHP_VERSION}'" docker build -f <path-to-Dockerfile> -t local/thinkphp:v${THINKPHP_VERSION} . fi
if [[ -n $(docker container ls | grep -v mytp5) ]]; then echo "create container 'mytp5'" docker create -p 8080:80 --name mytp5 local/thinkphp:v${THINKPHP_VERSION} fi
if [[ -n $(docker ps | grep -v mytp5 )]]; then echo "run conatiner 'mytp5'" docker start mytp5 fi