docker
安装docker[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jZSrMR1a-1607762393595)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605364846284.png)][外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uTt7HSEX-160
安装docker
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jZSrMR1a-1607762393595)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605364846284.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uTt7HSEX-1607762393596)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605364965075.png)]
3.清除以前的版本
官网地址:https://docs.docker.com/engine/install/centos/
docker安装第一步
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SjGOL5Ke-1607762393597)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\160541968161.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hwzROSqX-1607762393597)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605420050453.png)]
docker安装第二步
yum install -y yum-utils
docker安装第三步
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
docker安装第四步
更新yum软件包
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io
docke启动
systemctl start docker
查看docker进程
查看安装的Docker版本:docker version
[root@dalei ~]# ps -ef |grep docker
root 1990 1 0 14:21 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 2152 30596 0 14:21 pts/0 00:00:00 grep --color=auto docker
运行hello-world
docker run hello-world
查看镜像
docker images
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3XNvzPqC-1607762393598)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605422206762.png)]
宝塔面板查看命令
[root@dalei ~]# /etc/init.d/bt default
==================================================================
BT-Panel default info!
==================================================================
外网面板地址: http://101.132.144.73:8888/d709a4a2
内网面板地址: http://172.17.5.249:8888/d709a4a2
*以下仅为初始默认账户密码,若无法登录请执行bt命令重置账户/密码登录
username: oru2qlgz
password: ee9a0029
If you cannot access the panel,
release the following panel port [8888] in the security group
若无法访问面板,请检查防火墙/安全组是否有放行面板[8888]端口
==================================================================
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pshOIM7I-1607762393599)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605424806891.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ri0ithNC-1607762393600)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605424995677.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zTthjhsW-1607762393601)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425154271.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-E9yE1t9c-1607762393601)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425412314.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-a7XCm8kK-1607762393602)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425473516.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3nqoJOWF-1607762393602)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425428520.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-A9RRxMIB-1607762393603)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425537822.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-egrE2u7b-1607762393604)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425585011.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ok7eKNsL-1607762393604)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425693627.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Tz7yfHuu-1607762393604)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425863912.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cKbhLmoW-1607762393604)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605425986361.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sxyzvr5p-1607762393604)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605426028064.png)]
Docker的学习:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-svSJ6fTL-1607762393605)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605426496949.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nK3hiX3j-1607762393606)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605426796654.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UeLWlMZH-1607762393606)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605426936626.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-n44GeCR9-1607762393607)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427071197.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vNOa3S5N-1607762393607)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427357350.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tX3y0sF2-1607762393607)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427376650.png)]
3.配置镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://79xej63t.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CzeM324q-1607762393608)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427442079.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d3NJXA40-1607762393608)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427516307.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dN5LhAwv-1607762393609)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427604579.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kKhMMWHU-1607762393609)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605427707839.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4nrHVrcA-1607762393610)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605428061277.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iUedtKH5-1607762393610)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605428083978.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ehECh55i-1607762393610)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605428454249.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2ellHm56-1607762393610)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605428465121.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JFuQWpUR-1607762393611)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605428769886.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Alj3azXo-1607762393612)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605429275827.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-N9VesIhu-1607762393612)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605429336897.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kE7BI1XS-1607762393612)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605430705606.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0LUrnq12-1607762393613)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605431191110.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8g7nPhYR-1607762393614)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605431376227.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JmToskkT-1607762393614)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605433877432.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VtUP3Gbv-1607762393615)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605434400593.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rprukF8x-1607762393615)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605434644882.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OYfAhUVG-1607762393615)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605435181520.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QAnq2RLm-1607762393616)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605435345780.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C716Rplm-1607762393616)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605437109639.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gG3a62A9-1607762393617)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605437335870.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JSthiP5y-1607762393618)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605438130772.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-trWVae3c-1607762393618)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605438264498.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s2pB4alj-1607762393618)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605438415002.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OusteWyE-1607762393618)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605438836174.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qAzJ8zLD-1607762393618)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605439527608.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AlEKEq0S-1607762393619)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605439592087.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FrhZPOf8-1607762393620)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605439920172.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-v53yEojd-1607762393620)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605439959979.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-h0YCdFX2-1607762393620)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605442587157.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NckCUVtv-1607762393621)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605442752453.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KFipaAvM-1607762393621)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605443133606.png)]
端口暴露的概念
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ABS6oOw3-1607762393622)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605443392347.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lMlzwViT-1607762393622)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605443637060.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DtTYAikp-1607762393622)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605453417604.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HKR9iv7z-1607762393623)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605528037500.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jLRX7HW8-1607762393623)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605528238463.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GylTegLs-1607762393623)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605528303146.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-feX7OA0s-1607762393623)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605528431099.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-j4D4CAuw-1607762393624)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605529596901.png)]
[root@dalei ~]# docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
d1e017099d17: Pull complete
717377b83d5c: Pull complete
Digest: sha256:f8c2b0a9ca640edf508a8a0830cf1963a1e0d2fd9936a64104b3f658e120b868
Status: Downloaded newer image for portainer/portainer:latest
5edb6eee4983ba08d6cccafa0cf30b49b5cdd6aa5e6eb604932e60daa07b129e
http://101.132.144.73:8088
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ygTo1arp-1607762393624)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605529897198.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Jqfjmphn-1607762393625)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605530025279.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7ZoqvWGf-1607762393625)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605530768254.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IrhqAgn5-1607762393625)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605530322514.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jJtgsTB0-1607762393626)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605530567591.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rysqhdNZ-1607762393626)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605530574534.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RkHHVP2O-1607762393626)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605531717116.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pCL1OPra-1607762393627)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605531815802.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gRdfW1wR-1607762393627)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605531838888.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8RIvNUEM-1607762393628)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605532007088.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8OPtfOeK-1607762393628)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605532398530.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vWBOibvV-1607762393628)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605532924174.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-glP63Ok0-1607762393628)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605532853748.png)]
[root@dalei ~]# docker commit -a="dalei" -m="add webapps app" 035155329b0e tomcat02:1.0
sha256:887da9a21d606d541471e3de38a8ac76f6e77d5807a3da576ad5c11adbe0531e
[root@dalei ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat02 1.0 887da9a21d60 6 seconds ago 653MB
<none> <none> 04409e160b74 38 seconds ago 653MB
tomcat latest 2703bbe9e9d4 4 days ago 648MB
nginx latest c39a868aad02 10 days ago 133MB
redis latest 62f1d3402b78 2 weeks ago 104MB
mysql 5.7 1b12f2e9257b 3 weeks ago 448MB
centos latest 0d120b6ccaa8 3 months ago 215MB
portainer/portainer latest 62771b0b9b09 3 months ago 79.1MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FOvoTgWg-1607762393629)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605533407861.png)]
容器数据卷
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pk2Km4mI-1607762393629)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605535807825.png)]
[root@dalei ~]# cd /home
[root@dalei home]# ls
admin ceshi redis www
[root@dalei home]# docker run -it -v /home/ceshi:/home centos /bin/bash
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd
Status: Downloaded newer image for centos:latest
[root@17c4834e900b /]#
[root@dalei home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17c4834e900b centos "/bin/bash" 54 seconds ago Up 53 seconds distracted_yonath
5edb6eee4983 portainer/portainer "/portainer" 2 hours ago Up 2 hours 0.0.0.0:8088->9000/tcp awesome_elbakyan
035155329b0e 2703bbe9e9d4 "catalina.sh run" 23 hours ago Up 23 hours 0.0.0.0:8081->8080/tcp crazy_williamson
2ffb016291b9 centos "/bin/bash" 27 hours ago Up 27 hours inspiring_tesla
[root@dalei home]# docker rm -f 2ffb016291b9
2ffb016291b9
[root@dalei home]# docker inspect 17c4834e900b
[
{
"Id": "17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6",
"Created": "2020-11-16T14:34:46.430772975Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 29512,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-11-16T14:34:46.933422121Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566",
"ResolvConfPath": "/var/lib/docker/containers/17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6/hostname",
"HostsPath": "/var/lib/docker/containers/17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6/hosts",
"LogPath": "/var/lib/docker/containers/17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6/17c4834e900bb5b4b520b36db94074699bee1fd5b4fe2de5440e1dfa729c3fe6-json.log",
"Name": "/distracted_yonath",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/home/ceshi:/home"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/a720637b8461d1be30f95905dc6ac7f3c6abaaa4261232c35848dd51958057ca-init/diff:/var/lib/docker/overlay2/0dd06eeacf2c68d33fc7a1353aa49554ea6375dd3e66f6aa07111f7405e32546/diff",
"MergedDir": "/var/lib/docker/overlay2/a720637b8461d1be30f95905dc6ac7f3c6abaaa4261232c35848dd51958057ca/merged",
"UpperDir": "/var/lib/docker/overlay2/a720637b8461d1be30f95905dc6ac7f3c6abaaa4261232c35848dd51958057ca/diff",
"WorkDir": "/var/lib/docker/overlay2/a720637b8461d1be30f95905dc6ac7f3c6abaaa4261232c35848dd51958057ca/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/home/ceshi",
"Destination": "/home",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "17c4834e900b",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20200809",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "155c3bdabc6afa8f74c808641222feface45317386e89fdfa24bba2d90527969",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/155c3bdabc6a",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "5e0b974007d8e79bf7307edf881af034b9baa0abbfc19b10dc59c805a830f1f2",
"Gateway": "172.18.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.18.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:12:00:05",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "eef38011cc7d45533cc62e5e2c8dde9a7c672b1e6736021bb223c7b80e33676c",
"EndpointID": "5e0b974007d8e79bf7307edf881af034b9baa0abbfc19b10dc59c805a830f1f2",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:05",
"DriverOpts": null
}
}
}
}
]
"Mounts": [
{
"Type": "bind",
"Source": "/home/ceshi",
"Destination": "/home",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ODUCbBbt-1607762393629)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605537621552.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4XDzKZRa-1607762393630)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605537821056.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RLYeg3e3-1607762393630)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605538181804.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-isEawxV9-1607762393631)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605538254266.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3JV1DBOw-1607762393631)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605540917598.png)]
启动我们的Mysql容器
root@dalei home]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7
f478495a78509de1be0c4f61d9079b9264d83834fdbfc726ae8e570165f314be
[root@dalei home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f478495a7850 mysql:5.7 "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 33060/tcp, 0.0.0.0:3310->3306/tcp mysql01
17c4834e900b centos "/bin/bash" 51 minutes ago Up 37 minutes distracted_yonath
5edb6eee4983 portainer/portainer "/portainer" 3 hours ago Up 3 hours 0.0.0.0:8088->9000/tcp awesome_elbakyan
035155329b0e 2703bbe9e9d4 "catalina.sh run" 24 hours ago Up 24 hours 0.0.0.0:8081->8080/tcp crazy_williamson
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8xDzKlEx-1607762393632)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605541568222.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mZIuXzIT-1607762393632)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605541999332.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YxADIEqE-1607762393632)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605542049112.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y9IWzrhl-1607762393633)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605542428162.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-G53FRPPK-1607762393634)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605614739410.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hSrYaOYq-1607762393634)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605615227439.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HbSYMB41-1607762393634)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605615498457.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MdkJhJZ0-1607762393635)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605615680893.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oOWsxXPr-1607762393635)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605615857225.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NKs6rxDD-1607762393635)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616177479.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FzS4qbW0-1607762393635)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616275967.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PXAlphBo-1607762393635)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616347476.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yXqnPo6Q-1607762393636)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616401642.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YC7iZe9m-1607762393637)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616650724.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-g3NQrO5K-1607762393637)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605616859187.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9O7ujhWO-1607762393637)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605617173774.png)]
DockerFile
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ub1NKHeN-1607762393638)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605617551240.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NvK0JdU2-1607762393639)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605617604997.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5dIkYaXQ-1607762393639)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605617732305.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3E0bsQAI-1607762393639)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605617904922.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-X3HuhDeq-1607762393640)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605618113124.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZFuJHhKX-1607762393640)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605618404539.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eYVJ0svx-1607762393640)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605618623251.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mXoHKVvD-1607762393641)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605618693394.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tOd6PONc-1607762393641)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605618810575.png)]
创建一个自己的centos
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5hF6NtWl-1607762393641)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605619786381.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yvjMBnye-1607762393641)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605619645181.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rHPIT0y3-1607762393641)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605619994982.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3KpTRRVQ-1607762393642)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620585815.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-x9Ura2R0-1607762393642)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620204876.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-V82nm1ec-1607762393643)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620359666.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-K6XCd1EP-1607762393644)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620710232.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Yc5mcuS9-1607762393644)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620931624.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ef4mCihl-1607762393644)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605621048538.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6fWPiDgh-1607762393644)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605620844371.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rFmEgzXv-1607762393645)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605621083563.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WvL0BZzA-1607762393645)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605621128935.png)]
实战Tomcat镜像
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mfaDHJAO-1607762393646)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605621279277.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FogM1QZI-1607762393646)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605622828548.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QIL7HZPp-1607762393647)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605622912739.png)]
4.启动镜像
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dtsdUTm9-1607762393648)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626030425.png)]
5.访问测试
6.发布项目
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gnApy8IY-1607762393648)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605625949158.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mVxuQmFx-1607762393648)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626149204.png)]
发布自己的镜像
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C1h8OEYm-1607762393648)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626418556.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-q4BDu7Op-1607762393649)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626431218.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1vIVBjZE-1607762393649)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626723480.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ju60LFrg-1607762393650)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605626734297.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Qr5jjdTw-1607762393650)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605627009808.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CyDZbFo4-1607762393650)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605627036325.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FH6qmmIC-1607762393650)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605627250476.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GKTV7Zhy-1607762393651)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605627538676.png)]
Docker网络
理解Docker0
移除所有的容器
[root@dalei ~]# docker rm -f $(docker ps -aq)
[root@dalei ~]# docker rmi -f $(docker images -aq)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KB8mGiyB-1607762393652)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605628082351.png)]
移除所有的镜像
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Eo1tI1De-1607762393652)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605627977177.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MJKaSw5L-1607762393652)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605628493159.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bxp7lrAZ-1607762393656)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605628663500.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9Z3rlH0S-1607762393656)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605704497875.png)]
原理
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-x6XsxLp7-1607762393656)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605705249284.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PopACu0x-1607762393656)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605705263501.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4GODxhAs-1607762393656)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605705416029.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tmJN6HgE-1607762393658)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605705670097.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CgnZtrq2-1607762393658)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605705993135.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xF4rVFew-1607762393658)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605706010471.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4CpFIpV8-1607762393658)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605706546374.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7siEG0Ae-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605706615219.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pQWJVPZj-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605707488242.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-r0g0XvaG-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605706732023.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mbIVTjXF-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605708002228.png)]
#查看hosts配置,在这里配置了tomcat02的配置
[root@dalei ~]# docker exec -it tomcat03 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 tomcat02 104ddec21caa
172.18.0.4 788f10904bcf
[root@dalei ~]#
–link 就是在我们的hosts配置增加了一个172.18.0.3 tomcat02 104ddec21caa
我们真实玩Docker已经不建议使用–link了
自定义网络!不适用docker0!
docker0问题:他不支持容器名连接访问!
自定义网络
查看所有的docker网络
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oy1TtSWA-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605708997574.png)]
网络模式
bridge:桥接docker(默认,自己创建也使用bridge模式)
none:不配置网络
host:和宿主机共享网络
container:容器网络连通!(用的少!局限很大)
测试
# 我们直接启动的命令 --net bridge,而这个就是我们的docker0
docker run -d -P --name tomcat01 tomcat
docker run -d -P --name tomcat01 --net bridge tomcat
# docker0特点,域名不能访问,--link可以打通连接
# 我们可以自定义一个网络!
# [root@dalei ~]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet
9aa3f1b75ea8478bf2709d504395e8de38642cc40c4eed3c0cbf7e63cc09e7e1
[root@dalei ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
eef38011cc7d bridge bridge local
5a6e12bad5ed host host local
9aa3f1b75ea8 mynet bridge local
ac897d376939 none null local
[root@dalei ~]#
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lqgZKOCz-1607762393659)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605710211548.png)]
启动两个容器
[root@dalei ~]# docker run -d -P --name tomcat-net-01 --net mynet tomcat
Unable to find image 'tomcat:latest' locally
latest: Pulling from library/tomcat
e4c3d3e4f7b0: Pull complete
101c41d0463b: Pull complete
8275efcd805f: Pull complete
751620502a7a: Pull complete
a59da3a7d0e7: Pull complete
9c0f1dffe039: Pull complete
576e3c6f47f8: Pull complete
c7e1b6c3ef84: Pull complete
0d1faf6119dd: Pull complete
2f260a3a72b2: Pull complete
Digest: sha256:95f7ca5b0cb707413ea0127f95f942ad5775e762068978a846b1b540eb3996fb
Status: Downloaded newer image for tomcat:latest
80f35721ca9f791ca911b3f79aa5447cbcb45d9ffd762b76773fefd641e48587
[root@dalei ~]# docker run -d -P --name tomcat-net-02 --net mynet tomcat
3907e262e2dc7d9ac5ba19cc5b758d3802e9c75395de114c3c3814546bf04ea6
[root@dalei ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest b7370dcde632 17 hours ago 649MB
[root@dalei ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3907e262e2dc tomcat "catalina.sh run" 12 seconds ago Up 11 seconds 0.0.0.0:32772->8080/tcp tomcat-net-02
80f35721ca9f tomcat "catalina.sh run" 20 seconds ago Up 18 seconds 0.0.0.0:32771->8080/tcp tomcat-net-01
[root@dalei ~]# docker network inspect mynet
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-am0ZAgW8-1607762393660)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605710513060.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-L7wO6mD2-1607762393660)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605710675752.png)]
我们自定义的网络docker都已经帮我们维护好了对应的关系,推荐我们平时这样使用网络!
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-P46FeFFV-1607762393660)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605710842960.png)]
网络连通
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s15iMnAC-1607762393662)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605711194695.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O94Ye518-1607762393662)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605711415487.png)]
#启动两个容器
docker run -d -P --name tomcat02 tomcat
docker run -d -P --name tomcat01 tomcat
# 测试打通 tomcat01 - mynet
#将mynet网络和tomcat01容器打通
#[root@dalei ~]# docker network connect mynet tomcat01
# 连通之后就是将 tomcat01 放到 mynet 网络下?
# docker network inspect mynet
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FS0BQGXx-1607762393662)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605711774121.png)]
# 01连通
[root@dalei ~]# docker exec -it tomcat01 ping tomcat-net-01
PING tomcat-net-01 (192.168.0.2) 56(84) bytes of data.
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=1 ttl=64 time=0.099 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=2 ttl=64 time=0.096 ms
64 bytes from tomcat-net-01.mynet (192.168.0.2): icmp_seq=3 ttl=64 time=0.091 ms
#02 是依旧打不通的
[root@dalei ~]# docker exec -it tomcat02 ping tomcat-net-01
ping: tomcat-net-01: Name or service not known
实战:部署Redis集群
# 创建网卡
[root@dalei ~]# docker network create redis --dubnet 172.38.0.0/16
unknown flag: --dubnet
See 'docker network create --help'.
[root@dalei ~]# docker network create redis --subnet 172.38.0.0/16
3f8608789921aa8a71678d6a0740b533c694dac3f0f99b445136efd838e350b6
[root@dalei ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
eef38011cc7d bridge bridge local
5a6e12bad5ed host host local
9aa3f1b75ea8 mynet bridge local
ac897d376939 none null local
3f8608789921 redis bridge local
[root@dalei ~]# docker network inspect redis
[
{
"Name": "redis",
"Id": "3f8608789921aa8a71678d6a0740b533c694dac3f0f99b445136efd838e350b6",
"Created": "2020-11-18T23:17:29.014293365+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.38.0.0/16"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
# 通过脚本创建六个redis配置
for port in $(seq 1 6);\
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat << EOF >/mydata/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \
-v /mydata/redis/node-${port}/data:/data \
-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.1${port} reids:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf; \
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
-v /mydata/redis/node-1/data:/data \
-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.11 reids:5.0.9-alpine3.11 reids-server /etc/redis/redis.conf
docker run -p 6372:6379 -p 16372:16379 --name redis-2 \
-v /mydata/redis/node-2/data:/data \
-v /mydata/redis/node-2/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.12 reids:5.0.9-alpine3.11 reids-server /etc/redis/redis.conf
docker run -p 6373:6379 -p 16373:16379 --name redis-3 \
-v /mydata/redis/node-3/data:/data \
-v /mydata/redis/node-3/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.13 reids:5.0.9-alpine3.11 reids-server /etc/redis/redis.conf
# 创建集群
redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1
SpringBoot你服务打包Docker镜像
1.构建springboot项目
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6vprMTqb-1607762393663)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605793614814.png)]
2.打包应用
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ptxuRKgE-1607762393663)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605793675819.png)]
3.编写dockerfie
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kbhgczva-1607762393663)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605793750901.png)]
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port:8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Lbc9Dl1f-1607762393663)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605793784318.png)]
4.构建镜像
[root@dalei idea]# ls
demo-0.0.1-SNAPSHOT.jar Dockerfile
[root@dalei idea]# docker build -t dalei777 .
5.发布运行
[root@dalei idea]# ls
demo-0.0.1-SNAPSHOT.jar Dockerfile
[root@dalei idea]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dalei666 latest 816e23050745 21 minutes ago 660MB
dalei777 latest 816e23050745 21 minutes ago 660MB
java 8 d23bdf5b1b1b 3 years ago 643MB
[root@dalei idea]# docker run -d -p 8081:32777 --name dalei-springboot-web1 dalei777
6.测试访问
[root@dalei idea]# curl localhost:32777/hello
卸载Docler
-
Uninstall the Docker Engine, CLI, and Containerd packages:
$ sudo yum remove docker-ce docker-ce-cli containerd.io
-
Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker
Docker Compose
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Zj3SMbgM-1607762393665)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605797991415.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JdceKGr3-1607762393665)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605798276206.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-v9ilLKUp-1607762393665)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605798674239.png)]
安装
1.下载
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 这个可能快点
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Pydaf0fh-1607762393665)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605799653937.png)]
2.授权
sudo chmod +x /usr/local/bin/docker-compose
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YsAzOUld-1607762393666)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605799904936.png)]
体验
地址:https://docs.docker.com/compose/gettingstarted/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xRrZ7EmM-1607762393666)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1605800786996.png)]
1.准备工作
yum install python-pip # pip 是python包管理工具
yum -y install epel-release # 报错的话执行
2.为项目创建目录
$ mkdir composetest
$ cd composetest
3.的项目的目录中创建一个名为app.py
的文件,内容如下:
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
在本例中,redis是应用程序网络上redis容器的主机名,我们使用的Redis是默认端口6379
4.在项目目录中,创建名为requirements.txt
的文件,内容
flask
redis
5.在项目目录中,创建名为Dockerfile
的文件
FROM python:3.6-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
6.在项目目录中创建一个名为docker-compose.yml
的文件
version: "3.8"
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: "redis:alpine"
[root@izuf6bhe673f5t3au2vpp7z composetest]# ll
total 16
-rw-r--r-- 1 root root 515 Nov 22 15:15 app.py
-rw-r--r-- 1 root root 140 Nov 22 15:22 docker-compose.yml
-rw-r--r-- 1 root root 110 Nov 22 15:17 Dockerfile
-rw-r--r-- 1 root root 12 Nov 22 15:15 requirements.txt
[root@izuf6bhe673f5t3au2vpp7z composetest]#
7.启动项目运行
Build and run your app with Compose
# docker-compose up
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wlGorsJm-1607762393667)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606023165123.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DaD6ujJx-1607762393667)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606026693042.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7l3CMopq-1607762393667)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606023272935.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Jg8fNncz-1607762393667)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606023653797.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9sfRKZ8g-1607762393668)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606031187839.png)]
如果在同一个网络下,我们可以直接通过域名访问。
停止:docker-compose down,ctrl+c,
体验总结:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iyH2ll5p-1607762393668)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606028867895.png)]
yaml规则
docker-compose.yaml核心。!
https://docs.docker.com/compose/compose-file/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tgOqCPYw-1607762393668)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606033269422.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-68oAPuej-1607762393669)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606033592095.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NjQi9LNt-1607762393669)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606033661269.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-W5pt73Sv-1607762393669)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606033945186.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QO71SUND-1607762393669)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606034567589.png)]
https://docs.docker.com/compose/wordpress/
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-h9MRgs8Q-1607762393670)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606034852375.png)]
实战:
1.创建一个springboot的工程,选中web和redis的依赖
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vtk3eM4x-1607762393671)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606036924673.png)]
2.创建一个控制器,其访问地址为:/hello
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xPDfTAhh-1607762393671)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606036995641.png)]
3.application.properties的配置
server.port=8088
spring.redis.host=redis
4.构建一个Dockerfile
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8088"]
EXPOSE 8088
ENTRYPOINT ["java","-jar","/app.jar"]
5.构建一个docker-compose.yaml
version: '3.8'
services:
daleiapp:
build: .
image: kuangapp
depends_on:
- redis
ports:
- "8088:8088"
redis:
image: "library/redis:alpine"
6.项目打包,然后把相关的文件移动到Linux的home的daleiapp文件下(/home/daleiapp)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tjpgEq2W-1607762393671)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606038447936.png)]
7.在服务器中,cd到daleiapp的目录中,然后执行docker-compose up命令,启动服务
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nEfq9KII-1607762393671)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606039504595.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-q4DVMQL0-1607762393672)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606038835492.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qwv1bBFo-1607762393672)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606040662474.png)]
[root@izuf6bhe673f5t3au2vpp7z ~]# curl localhost:8088
{"timestamp":"2020-11-22T10:24:56.439+00:00","status":404,"error":"Not Found","message":"","path":"/"}[root@izuf6bhe673f5t3au2vpp7z ~]# ^C
[root@izuf6bhe673f5t3au2vpp7z ~]# curl localhost:8088/hello
hello,dalei,thank you,views:30[root@izuf6bhe673f5t3au2vpp7z ~]#
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IC8Khtov-1607762393672)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606040939321.png)]
Docker Swarm
集群
购买服务器
4台服务器 2G!
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NVU6UWJj-1607762393673)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606042585293.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LYYrohvO-1607762393674)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606042627404.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iJOGVCGC-1607762393674)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606042649084.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Zdn1ds72-1607762393675)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606043311437.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UqpaV9fE-1607762393675)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606043444953.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XKdIsMDm-1607762393676)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606043525637.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-U7hE5XK0-1607762393676)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606043601244.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fr6EmPoB-1607762393676)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606043621487.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rXpQG4PO-1607762393677)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606046613135.png)]
How nodes work
Estimated reading time: 2 minutes
Docker Engine 1.12 introduces swarm mode that enables you to create a cluster of one or more Docker Engines called a swarm. A swarm consists of one or more nodes: physical or virtual machines running Docker Engine 1.12 or later in swarm mode.
There are two types of nodes: managers and workers.
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-D5tM7tX1-1607762393677)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606046840864.png)]
If you haven’t already, read through the swarm mode overview and key concepts.
搭建集群
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jgso2lsq-1607762393678)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606049924364.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ap1dHQLD-1607762393678)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606050019295.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vpUGS3US-1607762393678)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606135242792.png)]
初始化节点:[root@iZuf6071etwudh3wzp80qzZ ~]# docker swarm init --advertise-addr 172.30.177.123
docker swarm join 加入一个节点!
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-t7EYGXGA-1607762393678)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606050656633.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1xjP5PC8-1607762393679)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606050955882.png)]
# 获取令牌
docker swarm join-token manager 生成主节点令牌
docker swarm join-token worker 生成工作节点令牌
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FCFk3s3W-1607762393679)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606051282737.png)]
将其他工作节点也加入到主节点上去
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oNhJh8T3-1607762393680)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606051412038.png)]
将docker-4变成主节点
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OYm5PU5K-1607762393680)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606052319641.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JAOfRK9V-1607762393680)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606052338627.png)]
把后面的节点都搭建进去!
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mjTqzK93-1607762393681)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606052489366.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Q8Xf7Q1a-1607762393682)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606052579280.png)]
将其他节点离开命令: docker swarm leave
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-duNyqsqk-1607762393682)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606053401129.png)]
将工作节点3也变成主节点
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-E1oC0pkh-1607762393682)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606053747888.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1wfQoWFc-1607762393682)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606053820702.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zsylU7dO-1607762393683)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606054155502.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eYqPf4Vg-1607762393683)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606054428969.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XU4zmE9c-1607762393683)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606055057006.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RuytyeHG-1607762393684)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606130836163.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8aO5Wmyj-1607762393684)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606131137225.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VvPRlxyA-1607762393685)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606131284563.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z5ZN5eoq-1607762393685)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606133142965.png)]
动态扩缩容
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hqHVK2q4-1607762393685)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606134002071.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2WTpNE6e-1607762393685)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606134136027.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-STXiB5br-1607762393686)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606134176282.png)]
回滚为1个:
[root@iZuf6071etwudh3wzp80qzZ ~]# docker service update --replicas 1 my-nginx
my-nginx
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
[root@iZuf6071etwudh3wzp80qzZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZuf6071etwudh3wzp80qzZ ~]#
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UXp6uSvs-1607762393686)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606134651687.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8pWLYxnP-1607762393687)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606134917326.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FiuYlNwb-1607762393687)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606135047441.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Qwdhp1QI-1607762393687)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606135596531.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JsqRcO5u-1607762393688)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606136698534.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6sGXJEG4-1607762393688)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606136744993.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uxKay0xA-1607762393689)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606136886416.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VOMISD0K-1607762393689)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606136926326.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xqKxvjnT-1607762393689)(C:\Users\mr.chen\AppData\Roaming\Typora\typora-user-images\1606137330645.png)]
Docker Stack
Docker Secret
Docker Config
更多推荐
所有评论(0)