欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)

程序员文章站 2024-03-25 16:03:16
...

一.docker-machine简介

1.Docker Machine是Docker官方编排项目之一,负责在多种平台上快速安装docker环境
2.Docker Machine支持在常规Linux操作系统,虚拟化平台,openstack,公有云等不同环境下安装配置docker host
3.Docker Machine项目基于Go语言实现

二.创建docker-machine

1.下载docker-machine

[aaa@qq.com ~]# mv docker-machine-Linux-x86_64-0.16.1 /usr/local/bin/docker-machine
[aaa@qq.com ~]# chmod 777 /usr/local/bin/docker-machine

2.设置免密登陆远程主机

ssh-******
ssh-copy-id server3
ssh-copy-id server2

3.配置物理机环境

在物理机的默认发布目录下编辑yum源文件,下载并修改get-docker.sh文件的398行和462行,yum仓库中放入以下四个文件

[aaa@qq.com docker-ce]# yum install -y createrepo
[aaa@qq.com ~]# cd /var/www/html/
[aaa@qq.com html]# ls
docker-ce  docker-ce.repo  get-docker.sh  images  index.html  rhel7.6
[aaa@qq.com html]# cat docker-ce.repo 
[docker]
name=docker-ce
baseurl=http://172.25.13.250/docker-ce
gpgcheck=0
[aaa@qq.com html]# cd docker-ce/
[aaa@qq.com docker-ce]# createrepo .
Directory walk started
Directory walk done - 4 packages
Temporary output repo path: ./.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
[aaa@qq.com docker-ce]# ls
containerd.io-1.2.13-3.2.el7.x86_64.rpm
container-selinux-2.77-1.el7.noarch.rpm
docker-ce-19.03.12-3.el7.x86_64.rpm
docker-ce-cli-19.03.12-3.el7.x86_64.rpm
repodata

docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)
docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)
docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)

4.在server2,3上创建主机

创建主机的命令
[aaa@qq.com ~]# docker-machine create --driver generic --engine-install-url "http://172.25.13.250/get-docker.sh" --generic-ip-address 172.25.13.3 server3
Running pre-create checks...
Creating machine...
(server3) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with centos...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env server3

[aaa@qq.com ~]# docker-machine env server3
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://172.25.13.3:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/server3"
export DOCKER_MACHINE_NAME="server3"
# Run this command to configure your shell: 
# eval $(docker-machine env server3)

docker配置文件,复制到要安装docker环境的两台主机上
[aaa@qq.com sysctl.d]# cat docker.conf
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1

[aaa@qq.com ~]# scp /etc/sysctl.d/docker.conf server3:/etc/sysctl.d/
docker.conf                                   100%   75   107.4KB/s   00:00 

[aaa@qq.com sysctl.d]# scp /etc/sysctl.d/docker.conf server2:/etc/sysctl.d/   

[aaa@qq.com ~]# docker-machine create --driver generic --generic-ip-address 172.25.13.2 server2
Running pre-create checks...
Creating machine...
(server2) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with redhat...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env server2

显示已创建成功的主机
[aaa@qq.com ~]# docker-machine ls
NAME      ACTIVE   DRIVER    STATE     URL                      SWARM   DOCKER      ERRORS
server2   -        generic   Running   tcp://172.25.13.2:2376           v19.03.12   
server3   -        generic   Running   tcp://172.25.13.3:2376           v19.03.12   

有docker的端口2376
[aaa@qq.com .ssh]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3141/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      3236/master         
tcp        0      0 172.25.13.3:22          172.25.13.250:35510     ESTABLISHED 3400/sshd: aaa@qq.com 
tcp6       0      0 :::2376                 :::*                    LISTEN      8271/dockerd        
tcp6       0      0 :::22                   :::*                    LISTEN      3141/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      3236/master         

[aaa@qq.com ~]# netstat -antlp | grep :2376
tcp6       0      0 :::2376                 :::*                    LISTEN      4789/dockerd        

[aaa@qq.com .ssh]# cd /etc/systemd/system/docker.service.d/

[aaa@qq.com docker.service.d]# ls
10-machine.conf

[aaa@qq.com docker.service.d]# cat 10-machine.conf 
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2 --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic 
Environment=

docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)
docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)
docker环境多种平台上的自动化安装---docker-machine(docker machine简介,创建docker machine)