1. 部署基础环境
学习本章,请先按照如下教程部署Docker环境,
https://www.cmdschool.org/archives/2183
另外,我们还建议你先学习以下章节,
https://www.cmdschool.org/archives/2276
2 单物理机Docker的服务
In docker-m
2.1 配置Docker群集服务
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 resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "80:80" networks: - webnet networks: webnet:
注:配置文件执行以下内容,
– 从注册库中拉出云端的镜像
– 同时运行该镜像的5个实例
– 每个实例限制最大使用10%的CPU
– 每个实例限制最大使用50M的内存
– 重启策略,任意一个实例失败则重启容器
– 将主机的80端口映射到该web的80端口
– web通过称为负载均衡的网络指示容器共享80端口
– webnet使用默认设置定义网络(负载平衡覆盖网路)
2.1.2 群集初始化
su - docker docker swarm init
信息提示如下:
Swarm initialized: current node (ehwkpmpfi2ya5zs326bbac3yt) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-2o1l0zx4ow0av23rvffgi8827t6dk8zobmscph7ypscgplm61p-ejp2a1v7665uyw2yr0yoft3zv 10.168.0.60:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
2.1.3 部署应用
su - docker docker stack deploy -c docker-compose.yml getstartedlab
以上声明应用名称为“getstartedlab”,显示如下:
Creating network getstartedlab_webnet Creating service getstartedlab_web
2.2 服务的查看
2.2.1 查看服务
docker service ls
显示如下:
ID NAME MODE REPLICAS IMAGE PORTS j02kso7vyfcd getstartedlab_web replicated 5/5 userxxx/app-python:part1 *:80->80/tcp
注:留意服务的名称“getstartedlab_web”,因为下面要用到
2.2.2. 查看服务的节点
docker service ps getstartedlab_web
显示如下:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS ozztpffx7f4x getstartedlab_web.1 tanzhenchao/app-python:part1 localhost.localdomain Running Running 15 minutes ago n9sz0hlgsdjv getstartedlab_web.2 tanzhenchao/app-python:part1 localhost.localdomain Running Running 15 minutes ago xt91xdagxc1o getstartedlab_web.3 tanzhenchao/app-python:part1 localhost.localdomain Running Running 15 minutes ago vbae5prr7a10 getstartedlab_web.4 tanzhenchao/app-python:part1 localhost.localdomain Running Running 15 minutes ago 9dkq58a64dsw getstartedlab_web.5 tanzhenchao/app-python:part1 localhost.localdomain Running Running 15 minutes ago
2.2.3 显示服务的ID
docker container ls -q
显示如下:
e2658519c08f 02858696ea2c 483c3b126b65 cc7197e0d270 373c9fbc450c
2.3 测试运行
curl http://127.0.0.1:80
信息显示如下:
<h3>Hello World!</h3><b>Hostname:</b> d9fd94aecd2e<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>
参阅文档:
=============================
基本概念:
—————————–
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/
没有评论