docker run -it -name blog-auto-publish ubuntu:18.04 /bin/bash
apt update
apt install git
apt install vim
rm -rf /etc/apt/sources.list
vim /etc/apt/sources.list
script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#!/usr/bin/env bash service fcgiwrap start service nginx start cd /my-blog/blog/ && nohup hexo g --watch >/my-blog/logs/hexo-generate.log 2>&1 & tail -f -n 500 /my-blog/logs/publish.log /my-blog/logs/hexo-generate.log /var/log/nginx/error.log /var/log/nginx/access.log
不使用 dockerfile 来构建,直接使用 docker commit
1
docker commit -c 'CMD ["sh", "/my-blog/bash/init.sh"]' -c "EXPOSE 80" -c "EXPOSE 8080" -a "JoyLau" -m "JoyLau's Blog Docker Image" blog nas.joylau.cn:5007/joy/blog.joylau.cn:2.1
优化更新记录 [2020-04-02]
更新脚本:
init.sh
1 2 3 4 5 6 7 8
#!/usr/bin/env bash echo"Hello! log file in /my-blog/logs/publish.log" service fcgiwrap start service nginx start su - www-data -c "cd /my-blog/blog/ && git pull" cd /my-blog/blog/ hexo g --watch | tee -a /my-blog/logs/publish.log
publish.sh
1 2 3 4 5
#!/bin/bash echo"Content-Type:text/html" echo"" echo"ok\r\n" /my-blog/bash/pull-deploy.sh | tee -a /my-blog/logs/publish.log
pull-deploy.sh
1 2 3 4 5
#! /usr/bin/env bash echo"Prepare to update Blog Posts....." cd /my-blog/blog/ git pull
优化更新记录 [2020-04-07]
新增 republish.sh
1 2 3 4
#!/usr/bin/env bash echo"prepare republish......" cd /my-blog/blog/ hexo clean && hexo g
修改 init.sh
1 2 3 4 5
#!/usr/bin/env bash echo"Hello! log file in /my-blog/logs/publish.log" service fcgiwrap start service nginx start su - www-data -c "cd /my-blog/blog/ && git pull && hexo g --watch | tee -a /my-blog/logs/publish.log"
#!/bin/bash set -e if [ "$1" = '/my-blog/bash/init.sh' -a "$(id -u)" = '0' ]; then service nginx start service fcgiwrap start echo"☆☆☆☆☆ base service has started. ☆☆☆☆☆" exec gosu www-data "$0""$@" fi exec"$@"
init.sh
1 2 3 4 5 6 7
#! /bin/bash cd /my-blog echo"☆☆☆☆☆ your git repo is [$GIT_REPO] ; branch is [$BRANCH]. ☆☆☆☆☆" git clone -b $BRANCH --progress $GIT_REPO blog cd blog cnpm install -d hexo g --watch --debug | tee -a /my-blog/logs/genrate.log
#!/bin/bash echo"Content-Type:text/html" echo"" echo"<h1>ok</h1>" echo"<h3>Prepare to update Blog Posts.....</h3>" cd /my-blog/blog/ git pull
republish.sh
1 2 3 4 5 6 7
#!/bin/bash echo"Content-Type:text/html" echo"" echo"<h1>ok</h1>" echo"<h3>republish blog.....</h3>" cd /my-blog/blog hexo g --force
sources.list
1 2 3 4 5 6 7 8 9
deb http://mirrors.163.com/debian/ stretch main non-free contrib deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib deb-src http://mirrors.163.com/debian/ stretch main non-free contrib deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
启动
1
docker run -d --restart always --name blog -p 8001:80 -p 8002:8081 nas.joylau.cn:5007/joy/blog.joylau.cn:3.0