Get Started with Docker 1.12 on Raspberry Pi

I have put this guide together to help you get started with Docker 1.12 on your Raspberry Pi. For simplicity we will use the default operating system for the Pi - called Raspbian. This guide currently works with most models of Raspberry Pi and I’d recommending using the Model B 2/3 or Zero.


Raspberry Pi cluster

Raspberry Pi Zero Cluster

Don’t know what Docker is yet or what you could use it for? Check out Understanding Docker from the offical docs.

Already using Docker on your Pi?

Head straight over to my Live Swarm Deep Dive video where we connect multiple Raspberry Pis to together to create a Docker Swarm.

more >>

Hexo安装和配置

1. Git安装和设置

  • github
    1
    2
    brew install git          #Mac电脑使用brew安装 
    sudo apt-get install git #Ubuntu系统使用这条命令安装

然后设置好git账户
使用Github Page搭建博客, 需要在github建立仓库,仓库名为username.github.io

  • gitcafe
    因为github速度稍微慢一点,所以用作备份站,主站用国内的gitcafe。

1) 先到https://gitcafe.com/projects/new页面注册一个新的项目,项目名需要与你的用户名相同,默认分支选择gitcafe-pages,项目主页也是相同的 http://username.gitcafe.com

2) 采用和github同样的key文件,在 ~/.ssh/id_rsa.pub
如果没有,单独生成一个ssh-key

ssh-keygen -t rsa -C "emailaddress" -f ~/.ssh/gitcafe
在SSH的文件夹下,可以看到gitcafe私钥和公钥文件:
gitcafe gitcafe.pub
生成配置文件:

touch ~/.ssh/config
添加以下内容:
Host gitcafe.com www.gitcafe.com IdentityFile ~/.ssh/gitcafe
3) 登录网站,将SSH文件夹下的 GitCafe.pub 中的内容复制到公钥框中即可。

4) 测试是否连上,共用的key,输入:
ssh -T git@gitcafe.com -i ~/.ssh/id_rsa
单独的key,输入:
ssh -T git@gitcafe.com -i ~/.ssh/gitcafe

2. Node.js安装

brew install node #最新版的node.js的包中已经集成了npm包管理工具
使用以下命令验证是否安装成功
node -v npm -v
如果运行hexo命令时,发现错误:
-bash: hexo: command not found
是没有指定nodejs所致。可以使用下面方法解决:

如果机器没有安装过node,那么首先brew install nvm安装nvm。

其次需要在shell的配置文件(/.bashrc, ~/.profile, or ~/.zshrc)中添加如下内容:
`
export NVM_DIR=
/.nvm
source $(brew –prefix nvm)/nvm.sh
然后设置别名
nvm ls

#v0.12.7

nvm use 0.12.7

#Now using node v0.12.7

nvm alias default 0.12.7

#default -> 0.12.7 (-> v0.12.7)
如果之前通过brew install node方式安装过node,那么需要先删除系统中存在的node:
brew remove –force node
sudo rm -r /usr/local/lib/node_modules

brew prune
sudo rm -r /usr/local/include/node

检查brew是否正常

brew doctor
`

3. Hexo安装与设置

Node, npm和Git都安装成功, 开始安装hexo
npm install hexo -g #-g表示全局安装, npm默认为当前项目安装 hexo version
如果遇到报错

1
2
3
{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

则用下列语句安装
npm install hexo --no-optional

Hexo使用命令:

1
2
3
4
5
6
cd ~/git
hexo init hexo #执行init命令初始化到你指定的hexo目录
cd hexo
npm install #install before start blogging
hexo generate #自动根据当前目录下文件,生成静态网页
hexo server #运行本地服务

浏览器输入http://localhost:4000就可以看到效果。

目录结构

1
2
3
4
5
6
7
8
9
10
11
.
├── .deploy #需要部署的文件
├── node_modules #Hexo插件
├── public #生成的静态网页文件
├── scaffolds #模板
├── source #博客正文和其他源文件, 404 favicon CNAME 等都应该放在这里
| ├── _drafts #草稿
| └── _posts #文章
├── themes #主题
├── _config.yml #全局配置文件
└── package.json

4. 添加博文

hexo new “postName” #新建博文,其中postName是博文题目
博文会自动生成在博客目录下source/_posts\postName.md

文件自动生成格式:

1
2
3
4
5
6
7
8
title: "It Starts with iGaze: Visual Attention Driven Networkingwith Smart Glasses"  #博文题目
date: 2014-11-21 11:25:38 #生成时间
tags: #标签, 多个标签也可以使用格式[tag1, tag2, tag3,...]
- tag1
- tag2
- tag3
categories: [cat1,cat2,cat3]
---

正文, 使用 Markdown 语法书写
如果不想博文在首页全部显示, 并能出现阅读全文按钮效果, 需要在你想在首页显示的部分下添加

more >>

How to setup Docker Monitoring

Docker monitoring of servers and containers is becoming necessary the more Docker hosts and containers we provision. This tutorial will walk you through how to glue together several different components in order to achieve Docker monitoring.

Components for Docker Monitoring

First things first. We assume that Docker is installed, configured, and running on your host before we begin. Please ensure you can connect to your Docker host with a Web Browser either locally or over a Public IP. The rest of the Tutorial we will refer to this as the DockerIP The below components will be used to create our Docker Monitoring solution.

cAdvisor - Google has been using containers for quite sometime and created cAdvisor to help monitor their infrastructure. This single tool alone is an amazing monitoring tool. It not only monitors your Docker containers but the Docker host as well without any configuratio by just running the cAdvisor container on your Docker host. Be sure to check out the cAdvisor GitHub for more documentation on the API and different configuration options.

more >>

Python socket – chat server and client with code example

Socket based chat application

In our previous article on socket programming in python we learned about the basics of creating a socket server and client in python. In this post we are going to write a very simple chat application in python that is powered by sockets.
The chat application we are going to make will be more like a chat room, rather than a peer to peer chat. So this means that multiple users can connect to the chat server and send their messages. Every message is broadcasted to every connected chat user. The construction is as simple as the theory.

Code

The code consists of 2 python scripts. First is the server and the other is the chat client.

more >>