技术Docker我是程序员;您好程先生;叫我序员就好了

使用Docker在阿里云ECS上面搭建Ghost轻博客

2015-01-05  本文已影响4976人  我家的猫叫夏夏

环境准备

需要阿里云ECS一台,使用的是镜像市场的镜像“Docker运行环境(Ubuntu 64位)”。

升级最新版本Docker

由于自带的版本为docker 1.2,所以升级最新版本

$ 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

升级成功如下:

# 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

系统自带的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系统image
# docker pull ubuntu:14.04
由于国内网络原因下载原image异常慢,建议使用国内的源比如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

启动一个container

# docker run -it ubuntu:14.04 /bin/bash
再打开一个ssh窗口查看已经启动的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   

启动之后就进入容器内部了,可以执行linux里面的命令

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

开始安装Ghost

apt-get update
apt-get install curl
apt-get install unzip
apt-get install git
curl -sL https://deb.nodesource.com/setup | sudo bash -
apt-get install -y nodejs
apt-get install -y build-essential
# curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

解压缩

# unzip -uo ghost.zip -d ghost

进入解压缩的ghost文件里面进行安装

# cd /ghost
# npm install --production

安装成功之后启动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

此时程序的监听ip为127.0.0.1,需要修改config.js

sed -i "s/127.0.0.1/0.0.0.0/g" config.js 

安装完毕,我们需要写一个简单的启动脚本start.sh

#! /bin/bash
cd /ghost
npm start --production

以后启动容器的时候执行此脚本就可以了。

/ghost/start.sh

制作新的image

退出之前的操作,然后这个容器就自动停止了

# 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一个新的image

docker commit d67282e72ec6 ghost:v1

查询下新的images

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ghost               v1                  e66b3df554f4        10 hours ago        423.1 MB

然后重新运行一个容器,并把宿主机的80端口映射上去

docker run -d -p 80:2368 ghost:v1 /ghost/start.sh

通过http://182.92.100.246/ 就可以访问博客了。

ghost20150105092040.jpg

后记

cd /ghost/content/themes/StayPuft
# vi default.hbs
 <link href='//fonts.useso.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
上一篇下一篇

猜你喜欢

热点阅读