1. 部署基础环境
学习本章,请先按照如下教程部署Docker环境,
https://www.cmdschool.org/archives/2183
另外,我们还建议你先学习以下章节,
https://www.cmdschool.org/archives/2276
https://www.cmdschool.org/archives/2288
https://www.cmdschool.org/archives/2296
2 堆栈
In docker-m
2.1 基本概念
– 堆栈是一组相互关联的服务
– 堆栈间可以共享依赖关系
– 堆栈间可以相互协调和缩放
– 单个堆栈能够定义和协调整个应用程序的功能
2.2 配置Docker可视化
2.2.1 重新部署应用
2.2.1.1 修改Docker 服务配置文件
sudo vim /data/docker/app-python/docker-compose.yml
修改配置如下:
version: "3" services: web: # replace username/repo:tag with your name and image details image: userxxx/app-python:part1 deploy: replicas: 5 restart_policy: condition: on-failure resources: limits: cpus: "0.1" memory: 50M ports: - "80:80" networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - "8080:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: - webnet networks: webnet:
注:
– volumes,关键字声明可视化工具访问Docker的主机套接字文件
– placement,关键字声明服务只运行在管理节点,而不是成员节点
2.2.1.2 重新部署应用
su - docker docker stack rm getstartedlab docker stack deploy --with-registry-auth -c /data/docker/app-python/docker-compose.yml getstartedlab
2.2.2 检查应用部署
2.2.2.1 查看服务
docker service ls
显示如下:
ID NAME MODE REPLICAS IMAGE PORTS zh9nbwkig486 getstartedlab_visualizer replicated 1/1 dockersamples/visualizer:stable *:8080->8080/tcp ssjapvco6h9z getstartedlab_web replicated 5/5 tanzhenchao/app-python:part1 *:80->80/tcp
注:留意服务的名称“getstartedlab_web”,因为下面要用到
2.2.2.2 查看服务的节点
docker service ps getstartedlab_visualizer
显示如下:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 1em8z8bj0e7x getstartedlab_visualizer.1 dockersamples/visualizer:stable docker-m.cmdschool.org Running Running about a minute ago
注:请运行类似的命令检查之前的应用
2.2.3 配置防火墙
firewall-cmd --permanent --add-port 8080/tcp firewall-cmd --reload firewall-cmd --list-all
2.2.4 测试应用运行
2.3 配置访客统计器Redis服务
2.3.1 重新部署应用
2.3.1.1 修改Docker 服务配置文件
sudo vim /data/docker/app-python/docker-compose.yml
修改配置如下:
version: "3" services: web: # replace username/repo:tag with your name and image details image: userxxx/app-python:part1 deploy: replicas: 5 restart_policy: condition: on-failure resources: limits: cpus: "0.1" memory: 50M ports: - "80:80" networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - "8080:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: - webnet redis: image: redis ports: - "6379:6379" volumes: - "/data/docker/redis:/data" deploy: placement: constraints: [node.role == manager] command: redis-server --appendonly yes networks: - webnet networks: webnet:
注:以上增加的 配置直接调用Docker库中的Redis镜像运行redis服务,端口使用6379
2.3.1.2 创建配置所需的目录
sudo mkdir -p /data/docker/redis
2.3.1.3 重新部署应用
docker stack rm getstartedlab docker stack deploy --with-registry-auth -c /data/docker/app-python/docker-compose.yml getstartedlab
2.3.2 检查应用部署
2.3.2.1 查看服务
docker service ls
显示如下:
ID NAME MODE REPLICAS IMAGE PORTS mijz4jv17618 getstartedlab_redis replicated 0/1 redis:latest *:6379->6379/tcp h3jf83s9nr6v getstartedlab_visualizer replicated 1/1 dockersamples/visualizer:stable *:8080->8080/tcp 0nki1i54259z getstartedlab_web replicated 5/5 userxxx/app-python:part1 *:80->80/tcp
注:留意服务的名称“getstartedlab_web”,因为下面要用到
2.3.2.2 查看新服务的节点
docker service ps getstartedlab_redis
显示如下:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS hrdghreqh8aa getstartedlab_redis.1 redis:latest docker-m.cmdschool.org Running Running about a minute ago
注:请运行类似的命令检查之前的应用
2.3.3 可视化查看应用运行
参阅文档:
=============================
基本概念:
—————————–
https://docs.docker.com/get-started/#test-docker-version
安装Docker:
—————————–
https://docs.docker.com/install/
官方源地址:
—————————–
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
没有评论