2017年9月

docker入门

docker linux的安装

# 下载
sudo wget -qO- https://get.docker.com/ | sh # 下载docker安装shell脚本

# 添加用户到docker用户组
sudo usermod -aG docker xbf # 用户xbf添加到docker用户组

# 安装后启动服务
service docker start

# 使用阿里云docker加速器
https://cr.console.aliyun.com/#/accelerator

docker命令

docker build # 建立一个新的image
docker pull nginx # 下载一个iamge
docker run -p 8080:80 -d nginx # 运行容器
docker ps # 查看运行的docker程容器
docker stop 容器ID # 停止运行
docker commit -m '备注' # 提交新的images
docker rmi image的ID # 删除image

编写简单文件自创docker镜像

# 新增文件夹下Dockerfile文件
FROM alpine:latest
MAINTAINER zhorz
CMD echo "Hello Docker"

# 在新建的文件夹下运行命令: docker build -t hello_docker . 

# dockerfile语法
FROM base image
RUN 执行命令
ADD 添加文件
COPY 拷贝文件
CMD 执行命令
EXPOSE 暴露端口
WORKDIR 指定路径
MAINTAINER 维护者
ENV 设定环境变量
ENTRYPOINT 容器入
USER 指定用户
VOLUME mount point

简单分页类

protected $pageParam = 'p'; // 分页参数名 protected $rowList; // 每页显示条数 protected $totalList;// 总条数 protected $pages; // 分页数 protected $curPage; // 当前页数 protected $warp = '';// a标签外层 protected $curClass = 'on';// 当前页css类 protected $ajaxFunc = ''; // ajax分页函数名称 protected $patterm = array( '{msg}', '{first}', '{per}', '{cur}', '{next}', '{last}', ); protected $theme = "{first}{per}{cur}{next}{last}"; public function setWarp($warp) { $this->warp = $warp; } public function getWarp() { return $this->warp; } public function setCurClass($class) { $this->curClass = $class; } public function getCurClass() { return $this->curClass; } public function __construct($rowList, $totalList, $extraParam = array()) { $this->rowList = $rowList; $this->totalList = $totalList; $pageParam = $this->getPageParam(); $this->curPage = isset($_REQUEST["{$pageParam}"]) ? $_REQUEST["{$pageParam}"] : 1; $this->pages = ceil($this->totalList/$this->rowList); if ($this->curPage < 1) { $this->curPage = 1; } if ($this->curPage > $this->pages) { $this->curPage = $this->pages; } $this->extraParam = $extraParam; } protected function format($html) { $warp = $this->getWarp(); if (!empty($warp) && !empty($html)) { return "<{$warp}>{$html}</{$warp}>"; } return $html; } protected function buildUrl($num) { $queryParmas = ''; $name = $this->getPageParam(); $params = array(); if (!empty($_SERVER['QUERY_STRING'])) { $arr = explode('&', $_SERVER['QUERY_STRING']); foreach ($arr as $li) { list($k, $v) = explode('=', $li); $params[$k] = $v; } } $params[$name] = $num; if (!empty($this->extraParam)) { $params = array_merge($params, $this->extraParam); } $i = 0; foreach ($params as $k => $v) { $i == 0 ? ($queryParmas .= "{$k}={$v}") : ($queryParmas .= "&{$k}={$v}");$i++; } if (!empty($this->ajaxFunc)) { $param = array(); if (!empty($this->extraParam)) { $param = array_values($this->extraParam); } array_unshift($param, $num); $param = implode(',', $param); return "javascript:{$this->ajaxFunc}({$param});"; } else { return str_replace(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?')), "", $_SERVER['REQUEST_URI']) . '?' . $queryParmas; } } protected function buildMsg() { return "共{$this->pages}页, 当前第{$this->curPage}页"; } protected function buildFirstPage() { $html = ''; if ($this->curPage > 1) { $url = $this->buildUrl(1); return "<a href='$url'>首页</a>"; } return $html; } protected function buildPerPage() { $html = ''; if ($this->curPage != 1) { $url = $this->buildUrl($this->curPage - 1); return "<a href='$url'><</a>"; } return $html; } protected function buildNextPage() { $html = ''; if ($this->curPage != $this->pages) { $url = $this->buildUrl($this->curPage + 1); return "<a href='$url'>></a>"; } return $html; } protected function buildLastPage() { $html = ''; if ($this->curPage < $this->pages) { $url = $this->buildUrl($this->pages); return "<a href='$url'>尾页</a>"; } return $html; } protected function buildCurPage() { $off = 3; $count = $this->pages; $cur = $this->curPage; if ($count > 2*$off + 1) { if ($cur < $off + 1) { $first = 1; } else { $first = $cur - $off; } $last = $first + 2*$off; if ($last > $count) { $last = $count; $first = $last- 2*$off; } } else { $first = 1; $last = $count; } $html = ''; for ($i = $first; $i <= $last; $i++) { $url = $this->buildUrl($i); $html .= $this->format("<a href='$url'" . (($i==$this->curPage) ? " class='{$this->getCurClass()}'" : "") . ">$i</a>"); } return $html; } public function fetch($type = 1, $ajaxFunc = '') { if ($type == self::AJAX_PAGE) { $this->ajaxFunc = $ajaxFunc; } $content = str_replace($this->patterm, array( $this->buildMsg(), $this->format($this->buildFirstPage()), $this->format($this->buildPerPage()), $this->buildCurPage(), $this->format($this->buildNextPage()), $this->format($this->buildLastPage()), ), $this->theme); return $content; } public function getPageParam() { return $this->pageParam; } public function setPageParam($pageParam) { return $this->pageParam = $pageParam; } public function getTheme() { return $this->theme; } public function setTheme($theme) { return $this->theme = $theme; }

}