環(huán)境準(zhǔn)備
需要阿里云ECS一臺(tái),使用的是鏡像市場(chǎng)的鏡像“Docker運(yùn)行環(huán)境(Ubuntu 64位)”拍屑。
升級(jí)最新版本Docker
由于自帶的版本為docker 1.2途戒,所以升級(jí)最新版本
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo sh -c "echo deb https://get.docker.com/ubuntu docker main\
> /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
升級(jí)成功如下:
# docker version
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8
下載images
系統(tǒng)自帶的images為:
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos6 redis 5be6d903898f 10 weeks ago 350.5 MB
centos centos6 68edf809afe7 3 months ago 212.7 MB
下載最新ubuntu系統(tǒng)image
# docker pull ubuntu:14.04
由于國(guó)內(nèi)網(wǎng)絡(luò)原因下載原image異常慢,建議使用國(guó)內(nèi)的源比如docker.cn或者使用https://www.daocloud.io的加速器僵驰。
# docker pull docker.cn/docker/ubuntu:14.04
下載完成如下
# docker pull ubuntu:14.04
Pulling repository ubuntu
8eaa4ff06b53: Download complete
511136ea3c5a: Download complete
3b363fd9d7da: Download complete
607c5d1cca71: Download complete
f62feddc05dc: Download complete
Status: Downloaded newer image for ubuntu:14.04
可以再看下images
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 8eaa4ff06b53 3 days ago 188.3 MB
ubuntu 14.04.1 8eaa4ff06b53 3 days ago 188.3 MB
ubuntu latest 8eaa4ff06b53 3 days ago 188.3 MB
ubuntu trusty 8eaa4ff06b53 3 days ago 188.3 MB
centos6 redis 5be6d903898f 10 weeks ago 350.5 MB
centos centos6 68edf809afe7 3 months ago 212.7 MB
啟動(dòng)一個(gè)container
# docker run -it ubuntu:14.04 /bin/bash
再打開(kāi)一個(gè)ssh窗口查看已經(jīng)啟動(dòng)的container
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d67282e72ec6 ubuntu:14.04 "/bin/bash" 10 hours ago Up 4 seconds condescending_pare
啟動(dòng)之后就進(jìn)入容器內(nèi)部了喷斋,可以執(zhí)行l(wèi)inux里面的命令
root@d67282e72ec6:/# uname -a
Linux d67282e72ec6 3.13.0-30-generic #54-Ubuntu SMP Mon Jun 9 22:45:01 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
開(kāi)始安裝Ghost
- 安裝基礎(chǔ)環(huán)境
還是在上一步啟動(dòng)的container中安裝必要的軟件環(huán)境
apt-get update
apt-get install curl
apt-get install unzip
apt-get install git
- 安裝Node.js環(huán)境
curl -sL https://deb.nodesource.com/setup | sudo bash -
apt-get install -y nodejs
apt-get install -y build-essential
- 安裝并運(yùn)行 Ghost
下載最新版的Ghost安裝包
# curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
解壓縮
# unzip -uo ghost.zip -d ghost
進(jìn)入解壓縮的ghost文件里面進(jìn)行安裝
# cd /ghost
# npm install --production
安裝成功之后啟動(dòng)ghost
# npm start
> ghost@0.5.7 start /ghost
> node index
Migrations: Database initialisation required for version 003
Migrations: Creating tables...
Migrations: Complete
Ghost is running in development...
Listening on 127.0.0.1:2368
Url configured as: http://localhost:2368
Ctrl+C to shut down
此時(shí)程序的監(jiān)聽(tīng)ip為127.0.0.1,需要修改config.js
sed -i "s/127.0.0.1/0.0.0.0/g" config.js
安裝完畢蒜茴,我們需要寫(xiě)一個(gè)簡(jiǎn)單的啟動(dòng)腳本start.sh
#! /bin/bash
cd /ghost
npm start --production
以后啟動(dòng)容器的時(shí)候執(zhí)行此腳本就可以了星爪。
/ghost/start.sh
制作新的image
退出之前的操作,然后這個(gè)容器就自動(dòng)停止了
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d67282e72ec6 ubuntu:14.04 "/bin/bash" 11 hours ago Exited (0) 48 minutes ago condescending_pare
commit一個(gè)新的image
docker commit d67282e72ec6 ghost:v1
查詢(xún)下新的images
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ghost v1 e66b3df554f4 10 hours ago 423.1 MB
然后重新運(yùn)行一個(gè)容器粉私,并把宿主機(jī)的80端口映射上去
docker run -d -p 80:2368 ghost:v1 /ghost/start.sh
通過(guò)http://182.92.100.246/ 就可以訪問(wèn)博客了顽腾。
后記
- 以上操作可以直接使用一個(gè)dockerfile來(lái)創(chuàng)建,后續(xù)補(bǔ)上诺核。
- 由于ghost使用谷歌字體抄肖,所以打開(kāi)很慢,建議更換360CDN的字體加速窖杀。
cd /ghost/content/themes/StayPuft
# vi default.hbs
<link href='//fonts.useso.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>