【docker使用系列】docker1.12安装和初步使用

本文背景

背景

最近闲着无事,准备玩一把k8s,作为核心,要升级一波docker。
这次直接安装docker1.12。查了资料,docker1.12的最显著特性就是内置了docker自身的swarm调度。

安装过程

参考去年的docker 1.10安装心得,整一次1.12。

下载rpm包并安装

yum install -y --nogpgcheck http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7/Packages/docker-engine-selinux-1.12.6-1.el7.centos.noarch.rpm
yum install -y --nogpgcheck http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7/Packages/docker-engine-1.12.6-1.el7.centos.x86_64.rpm

修改docker的systemd文件

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd --storage-driver=devicemapper --exec-opt native.cgroupdriver=systemd -D -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --pidfile=/var/run/docker.pid
ExecReload=/bin/kill -s HUP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

这里暴露2375是为了其他的docker client调用。

修改配置文件

发现/etc/sysconfig/docker不顶用了。谷歌了一番,发现配置文件目录变了/data/docker/daemon.json

{
"insecure-registries": [
"10.2.1.30:5000"
],
"registry-mirror": [
"https://csokz3oi.mirror.aliyuncs.com"
],
"graph":"/data/docker"
}

启动docker

systemctl restart docker.service

docker操作

docker1.12与1.10的区别

先看docker –help对比

果然是多了三个关键字:
docker node
docker swarm
docker service

docker1.12 实操

先看docker help和docker.hub.com。

docker login

命令作用:登录私有镜像仓库

docker login 10.2.1.30:5000

输入账号和密码,即可提示登录成功。

docker tag

命令作用:对docker镜像打标签
命令使用:

docker tag anjia0532/google-containers.kubernetes-dashboard-amd64:v1.6.3 10.2.1.30:5000/anjia0532/kubernetes-dashboard-amd64:v1.6.3

docker pull

这个命令不需要多说了,从中央仓库或者私有仓库拉取镜像

docker push

命令作用:向仓库推送镜像文件
命令使用:

docker push 10.2.1.30:5000/anjia0532/kubernetes-dashboard-amd64:v1.6.3

至于docker swarm模式,有时间再了解。