操作系统ubuntu14.04 16.04
v单机安装步骤:
#安装httpsca证书
apt-get install apt-transport-https ca-certificates
#添加GPG 密钥:
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
#测试环境为14.04添加apt源
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.listapt-get update
#安装linux-image-extra-*内核包,这些包能允许我们使用aufs存储驱动。
apt-getupdate && sudoapt-get install linux-image-extra-$(uname-r) linux-image-extra-virtual
#确保APT 现在是从设置的仓库中下载Docker的.
apt-cachepolicy docker-engine
apt-getinstall docker-engine
#查看版本是否为17.*
docker–version
dockerinfo
v服务配置文件(添加监听docker2375端口,添加私有仓库等):§Ubuntu14:/etc/default/docker
DOCKER_OPTS=“-Hunix:///var/run/docker.sock -H 0.0.0.0:2375 --insecure-registry 私有仓库IP:PORT“
§Ubuntu16:/etc/default/docker /lib/systemd/system/docker.service
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/dockerdaemon -H fd:// $DOCKER_OPTS
#systemctldaemon-reload
#servicedocker restart
§Centos 6+:/lib/systemd/system/docker.servicev参考官方文档§https://docs.docker.com/engine/installation/
v多主机docker安装docker-machine
v参考说明:https://docs.docker.com/machine/install-machine/#install-machine-directly
v安装
#curl -L https://github.com/docker/machine/releases/download/v0.13.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
v查看版本:#docker-machineversion
下载脚本
scripts=( docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash ); for i in "${scripts[@]}"; do sudo wget https://raw.githubusercontent.com/docker/machine/v0.13.0/contrib/completion/bash/${i} -P /etc/bash_completion.d; done
配置环境变量写入文件~/.bashrc
PS1='[u@h W$(__docker_machine_ps1)]$ '
创建machine要求能无密码远程登录主机
ssh-keygen -trsa
ssh-copy-id 远程端主机IP如21.1.1.2
v创建主机
docker-machine create --driver generic --generic-ip-address=21.1.1.2 --generic-engine-port=2375(默认为2376) --generic-ssh-key~/.ssh/id_rsa --engine-insecure-registry=私有仓库地址:端口 主机名
v管理machine
查看machine
docker-machine ls
docker-machine env docker-pc6
eval $(docker-machine env docker-pc6)
查看环境变量
echo $DOCKER_HOST
查看当前操控主机
docker-machine active
查看IP
docker-machine ip host1
主机间拷贝文件
docker-machine scp host1 host2
获取Docker主机地址
docker-machine ip default
设置本地主机
apt-get install -y virtualbox-qt
docker-machine create -d virtualbox default
docker-machine ip default
eval $(docker-machine env default)
v配置文件
ubuntu 14:/etc/default/docker
重启docker service docker restart
ubuntu 16:vim/etc/systemd/system/docker.service.d/10-machine.conf
systemctl daemon-reload&&service docker restart
单机安装和使用docker-machine安装的区别
1、单机安装,修改配置文件后,可开放各docker主机的2375端口,直接通过命令docker -H ip:2375 ps/images查看和控制目标主机中的镜像和容器
2、通过docker-machine安装,可通过docker-machine修改环境变量,访问和控制目标主机中的镜像和容器,通过tlsverify。