==============================================================
dockerV17.12

卸载之前的版本
sudo yum remove docker \
docker-common \
docker-selinux \
docker-engine
安装依赖
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

安装docker仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装docker
sudo yum install docker-ce

启动docker
sudo systemctl start docker
run test实例子
sudo docker run hello-world

==============================================================
配置阿里云加速,登录阿里云镜像服务
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://b0dvz7wc.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

搜索镜像
docker search XXX

下载镜像
docker pull daocloud.io/centos:7

查看镜像
docker images

删除镜像
docker rmi XXX

==============================================================
启动镜像
docker run --name mycentos -it daocloud.io/centos /bin/bash

查看启动的容器、所有的容器
docker ps
docker ps -a -l

启动容器
docker start 73768d606b2b

关闭容器
docker stop 73768d606b2b

删除容器
docker rm 73768d606b2b

==============================================================
进入容器1:两个窗口要同步显示,exit后又退出了
docker attach 73768d606b2b

进入容器2:exit后不退出
docker exec -it 73768d606b2b /bin/bash

==============================================================
下载nginx
docker pull daocloud.io/library/nginx:1.13.0-alpine

运行nginx:-P随机端口,-p指定端口映射
docker run -d -P daocloud.io/library/nginx:1.13.0-alpine
docker run -d -p 81:80 daocloud.io/library/nginx:1.13.0-alpine

查看端口
docker ps

访问nginx
http://192.168.56.13:32768/

查看日志
docker logs b4593d413442

==============================================================
数据挂载-1:docker的data目录是挂载在主机的/var/lib/docker/volumes/
docker run -it --name volume-test1 -v /data daocloud.io/centos

数据挂载-2:指定目录挂载用于开发方代码,docker的opt目录挂载到主机的opt
docker run -it --name volume-test2 -v /opt:/opt daocloud.io/centos

查看容器具体信息
docker inspect 8c0336c0f9c7

共用volume-test1的data目录,两个容器的data目录会同步
docker run -it --name test1 --volumes-from volume-test1 daocloud.io/centos

==============================================================
手动构建镜像
docker run --name mycentos -it daocloud.io/centos:7

添加epel源
rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

安装nginx
yum install -y nginx

查看容器的id
docker ps -a

基于容器id做镜像
docker commit -m "my nginx" e462a067a79e oldboyedu/mynginx:v1

启动镜像
docker run -it --name nginxv1 oldboyedu/mynginx:v1

vi /etc/nginx/nginx.conf
添加
daemon off;

提交生成镜像
docker commit -m "my nginx" da81140dc2d4 oldboyedu/mynginx:v2

启动v2
docker run -d -p 82:80 --name nginxv2 oldboyedu/mynginx:v2 nginx

==============================================================
使用Dockerfile
基础镜像信息
维护者信息
镜像操作指令
容器运行指令

制作Dockerfile文件

-# This docker file
-# VERSION 1
-# Author: LMK
-# Base image
FROM daocloud.io/centos:7
#MAINTAINER
MAINTAINER LMK limoukun@chinamte.com
#Commands
RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx
ADD index.html /usr/share/nginx/html/index.html
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx"]

制作镜像
docker build -t oldboyedu/myningx:v3 /opt/dockerfile/nginx/

启动镜像
docker run -d -p 83:80 oldboyedu/myningx:v3

==============================================================
上传镜像到阿里云

docker login --username=hi31318141@aliyun.com registry.cn-hangzhou.aliyuncs.com
密码lmkmike2451688
docker tag 3f8a4339aadd registry.cn-hangzhou.aliyuncs.com/chinamte/lmk:v1
docker push registry.cn-hangzhou.aliyuncs.com/chinamte/lmk:v1

从阿里云下载镜像
docker login --username=hi31318141@aliyun.com registry.cn-hangzhou.aliyuncs.com
密码lmkmike2451688
docker pull registry.cn-hangzhou.aliyuncs.com/chinamte/lmk:v1

==============================================================
创建私有镜像仓库(真实使用的话需要配置https及密码认证)
docker run -d -p 5000:5000 registry

在物理机
vi /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 192.168.2.75:5000' 其中--insecure-registry 192.168.56.13:5000
systemctl restart docker
打标签及上传
docker tag docker.io/nginx:latest 192.168.56.13:5000/ngingx:v1
docker push 192.168.56.13:5000/ngingx:v1

其他机器下载
docker pull 192.168.56.13:5000/ngingx:v1

===============================================================
docker网页管理

1)安装shipyard

curl -s https://shipyard-project.com/deploy | bash -s

Shipyard available at http://192.168.56.13:8080
Username: admin Password: shipyard

在其他节点执行增加节点
curl -sSL https://shipyard-project.com/deploy | ACTION=node DISCOVERY=etcd://192.168.56.12:4001 bash -s

如果想将安装重新来一遍
curl -sSL https://shipyard-project.com/deploy | ACTION=remove bash -s