zoukankan      html  css  js  c++  java
  • (八)Docker Swarm 搭建 Nginx 服务

    1. Nginx镜像

    docker-nginx的root路径是:/usr/share/nginx/html

    [root@Thor _data]# docker run -dit --name nginx -P -v my_volume:/usr/share/nginx/html nginx:latest
    
    [root@Thor _data]# ls
    50x.html  aliyun.jpg  index.html
    [root@Thor _data]# docker volume inspect my_volume
    [
        {
            "Driver": "local",
            "Labels": {},
            "Mountpoint": "/var/lib/docker/volumes/my_volume/_data",
            "Name": "my_volume",
            "Options": {},
            "Scope": "local"
        }
    ]
    [root@Thor _data]# docker container ls
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    462b38e12ef2        nginx:latest        "nginx -g 'daemon ..."   22 minutes ago      Up 22 minutes       0.0.0.0:32770->80/tcp    nginx
    [root@Thor _data]# 
    

    http://10.86.10.214:32770/aliyun.jpg

    2. Docker Swarm 搭建 Nginx 集群

    [root@Thor volumes]# docker volume ls
    DRIVER              VOLUME NAME
    local               my_volume
    [root@Thor volumes]# 
    [root@Thor volumes]# 
    [root@Thor volumes]# clear
    [root@Thor volumes]# 
    [root@Thor volumes]# docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    996812025ea1        bridge              bridge              local
    3996a5cca929        docker_gwbridge     bridge              local
    7f779eaf12fc        host                host                local
    00ea96ba8181        my-net              bridge              local
    bab9f30b8cbc        none                null                local
    [root@Thor volumes]# 
    [root@Thor volumes]# docker swarm init
    Swarm initialized: current node (nawy26ys5d8t35poovzca09gf) is now a manager.
    
    To add a worker to this swarm, run the following command:
    
        docker swarm join 
        --token SWMTKN-1-08lysjmybp1f2gi2z3myfy4rqjm5n0jy9h4ah3ap1uv7x16c9z-5plyyozoy6ty6p3vfmc9838y8 
        10.86.10.214:2377
    
    To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    
    [root@Thor volumes]# docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    996812025ea1        bridge              bridge              local
    3996a5cca929        docker_gwbridge     bridge              local
    7f779eaf12fc        host                host                local
    i9hsx10utcfw        ingress             overlay             swarm
    00ea96ba8181        my-net              bridge              local
    bab9f30b8cbc        none                null                local
    [root@Thor volumes]# docker node ls
    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    nawy26ys5d8t35poovzca09gf *  Thor      Ready   Active        Leader
    [root@Thor volumes]# docker service ls
    ID  NAME  MODE  REPLICAS  IMAGE
    [root@Thor volumes]# docker service create --replicas 3 -p 1992:80 --mount type=volume,source=my_volume,destination=/usr/share/nginx/html --name nginx nginx:latest
    vb34nrb7rc86rag1hkw20dcia
    [root@Thor volumes]# docker service ls
    ID            NAME   MODE        REPLICAS  IMAGE
    vb34nrb7rc86  nginx  replicated  1/3       nginx:latest
    [root@Thor volumes]# docker service ls
    ID            NAME   MODE        REPLICAS  IMAGE
    vb34nrb7rc86  nginx  replicated  3/3       nginx:latest
    [root@Thor volumes]# 
    [root@Thor volumes]# docker service ls
    ID            NAME   MODE        REPLICAS  IMAGE
    vb34nrb7rc86  nginx  replicated  3/3       nginx:latest
    [root@Thor volumes]# 
    [root@Thor volumes]# docker container ls
    CONTAINER ID        IMAGE                                                                           COMMAND                  CREATED             STATUS              PORTS                    NAMES
    3f4fc77d40f5        nginx@sha256:1b109555ad28bb5ec429422ee136c5f5ab5ee6faaeb518836a5c9a3b6436a1bd   "nginx -g 'daemon ..."   48 seconds ago      Up 47 seconds       80/tcp                   nginx.3.25xb0q9ai3a0n1egw3bbu2ofk
    e5275a076b6e        nginx@sha256:1b109555ad28bb5ec429422ee136c5f5ab5ee6faaeb518836a5c9a3b6436a1bd   "nginx -g 'daemon ..."   48 seconds ago      Up 48 seconds       80/tcp                   nginx.1.xg5lm0izzbnpp54j7grqliv8h
    7573ec039bbd        nginx@sha256:1b109555ad28bb5ec429422ee136c5f5ab5ee6faaeb518836a5c9a3b6436a1bd   "nginx -g 'daemon ..."   49 seconds ago      Up 48 seconds       80/tcp                   nginx.2.t55k1n9yxqdw3xdony4ypt5bs
    bb8e12657b50        google/cadvisor                                                                 "/usr/bin/cadvisor..."   3 weeks ago         Up 3 weeks          0.0.0.0:8080->8080/tcp   cadvisor
    [root@Thor volumes]# 
    [root@Thor volumes]# docker service ls
    ID            NAME   MODE        REPLICAS  IMAGE
    vb34nrb7rc86  nginx  replicated  3/3       nginx:latest
    [root@Thor volumes]# docker service --help
    
    Usage:  docker service COMMAND
    
    Manage services
    
    Options:
          --help   Print usage
    
    Commands:
      create      Create a new service
      inspect     Display detailed information on one or more services
      ls          List services
      ps          List the tasks of a service
      rm          Remove one or more services
      scale       Scale one or multiple replicated services
      update      Update a service
    
    Run 'docker service COMMAND --help' for more information on a command.
    [root@Thor volumes]# docker service ps
    "docker service ps" requires exactly 1 argument(s).
    See 'docker service ps --help'.
    
    Usage:  docker service ps [OPTIONS] SERVICE
    
    List the tasks of a service
    [root@Thor volumes]# docker service ps nginx
    ID            NAME     IMAGE         NODE  DESIRED STATE  CURRENT STATE               ERROR  PORTS
    xg5lm0izzbnp  nginx.1  nginx:latest  Thor  Running        Running about a minute ago         
    t55k1n9yxqdw  nginx.2  nginx:latest  Thor  Running        Running about a minute ago         
    25xb0q9ai3a0  nginx.3  nginx:latest  Thor  Running        Running about a minute ago         
    [root@Thor volumes]# docker service inspect nginx
    [
        {
            "ID": "vb34nrb7rc86rag1hkw20dcia",
            "Version": {
                "Index": 12
            },
            "CreatedAt": "2018-09-01T06:50:00.889456834Z",
            "UpdatedAt": "2018-09-01T06:50:00.890534652Z",
            "Spec": {
                "Name": "nginx",
                "TaskTemplate": {
                    "ContainerSpec": {
                        "Image": "nginx:latest@sha256:1b109555ad28bb5ec429422ee136c5f5ab5ee6faaeb518836a5c9a3b6436a1bd",
                        "Mounts": [
                            {
                                "Type": "volume",
                                "Source": "my_volume",
                                "Target": "/usr/share/nginx/html"
                            }
                        ],
                        "DNSConfig": {}
                    },
                    "Resources": {
                        "Limits": {},
                        "Reservations": {}
                    },
                    "RestartPolicy": {
                        "Condition": "any",
                        "MaxAttempts": 0
                    },
                    "Placement": {},
                    "ForceUpdate": 0
                },
                "Mode": {
                    "Replicated": {
                        "Replicas": 3
                    }
                },
                "UpdateConfig": {
                    "Parallelism": 1,
                    "FailureAction": "pause",
                    "MaxFailureRatio": 0
                },
                "EndpointSpec": {
                    "Mode": "vip",
                    "Ports": [
                        {
                            "Protocol": "tcp",
                            "TargetPort": 80,
                            "PublishedPort": 1992,
                            "PublishMode": "ingress"
                        }
                    ]
                }
            },
            "Endpoint": {
                "Spec": {
                    "Mode": "vip",
                    "Ports": [
                        {
                            "Protocol": "tcp",
                            "TargetPort": 80,
                            "PublishedPort": 1992,
                            "PublishMode": "ingress"
                        }
                    ]
                },
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 80,
                        "PublishedPort": 1992,
                        "PublishMode": "ingress"
                    }
                ],
                "VirtualIPs": [
                    {
                        "NetworkID": "i9hsx10utcfw3q6dxgx4stp7t",
                        "Addr": "10.255.0.4/16"
                    }
                ]
            },
            "UpdateStatus": {
                "StartedAt": "0001-01-01T00:00:00Z",
                "CompletedAt": "0001-01-01T00:00:00Z"
            }
        }
    ]
    [root@Thor volumes]# 
    
  • 相关阅读:
    zoj 3820 Building Fire Stations(树上乱搞)
    wxWidgets+wxSmith版电子词典
    Android异步载入全解析之IntentService
    HDU 3832 Earth Hour(最短路)
    Android 应用程序窗口显示状态操作(requestWindowFeature()的应用)
    HighChart学习-更新数据data Series与重绘
    sar使用说明
    xcode多target
    Creating Contextual Menus创建上下文菜单
    安卓开发11:操作控件
  • 原文地址:https://www.cnblogs.com/walkinginthesun/p/9570862.html
Copyright © 2011-2022 走看看