• Portainer实战


        Portainer是一个轻量级的Docker环境管理UI,可以管理docker host和docker swarm(我主要看中了能管理swarm这个,毕竟市面上能管理swarm的平台不多)。之所以说是轻量级的,是因为部署只有一个container,也可以使用二进制程序直接部署,不像rancher的部署,部署了一大堆container,而且portainer是跨平台的,windows和linux都可以部署,废话不多说,直接开干....

    环境

    ubuntu16.04-1 swarm manager portainer
    ubuntu16.04-2 swarm works portainer agent
    ubuntu16.04-3 swarm works portainer agent

        ps:环境还是之前文章的swarm集群环境

    部署

        独立容器启动

    docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /path/on/host/data:/data portainer/portainer

            ps:portainer的数据存储在容器内部的/data目录,这样容器重启的时候数据会丢失,所以要确保数据持久化

    docker run -d -p 9000:9000 --name portainer --restart always -v portainer_data:/data portainer/portainer -H tcp://<REMOTE_HOST>:<REMOTE_PORT>
    

            ps:-H 后面的remote是你想用portainert管理的docker

        stack方式启动

            下载启动stack文件

    curl -L https://portainer.io/download/portainer-agent-stack.yml -o portainer-agent-stack.yml

            以stack方式启动

    docker stack deploy --compose-file=portainer-agent-stack.yml portainer

        swarm service启动

    docker service create 
        --name portainer 
        --publish 9000:9000 
        --replicas=1 
        --constraint 'node.role == manager' 
        --mount type=bind,src=//path/on/host/data,dst=/data 
        portainer/portainer

        二进制启动

    wget https://github.com/portainer/portainer/releases/download/1.19.2/portainer-1.19.2-linux-amd64.tar.gz
    tar xvpfz portainer-1.19.2-linux-amd64.tar.gz
    cd /opt/portainer
    ./portainer --template-file "${PWD}/templates.json"

            ps:模板文件的内容下面会详细解释

    [
     {
        "type": 1,
        "title": "Registry",
        "description": "Docker image registry",
        "categories": ["docker"],
        "platform": "linux",
        "logo": "https://portainer.io/images/logos/registry.png",
        "image": "registry:latest",
        "ports": [
          "5000/tcp"
        ],
        "volumes": [{ "container": "/var/lib/registry"}]
      },
    ]

    验证

        访问

    http://172.31.68.241:9000/

        登录

        查看

        容器信息

    配置

        之前说过portainer可以以二进制程序直接部署,也可以在启动容器的时候直接在CLI设置参数,来修改portainer的默认行为,可使用的参数主要有如下:

          --help                     帮助
          --version                  查看版本信息
      -p, --bind=":9000"             指定portainer监听的地址和端口
      -a, --assets="./"              Path to the assets
      -d, --data="/data"             指定data数据目录
      -H, --host=HOST                Endpoint URL
          --external-endpoints=EXTERNAL-ENDPOINTS  
                                     定义外部的endpoints
          --no-auth                  禁止portainer的认证
          --no-analytics             Disable Analytics in app
          --tlsverify                TLS support
          --tlsskipverify            Disable TLS server verification
          --tlscacert="/certs/ca.pem"  
                                     Path to the CA
          --tlscert="/certs/cert.pem"  
                                     Path to the TLS certificate file
          --tlskey="/certs/key.pem"  Path to the TLS key
          --ssl                      Secure Portainer instance using SSL
          --sslcert="/certs/portainer.crt"  
                                     Path to the SSL certificate used to secure the Portainer instance
          --sslkey="/certs/portainer.key"  
                                     Path to the SSL key used to secure the Portainer instance
          --sync-interval="60s"      Duration between each synchronization via the external endpoints source
          --snapshot                 Start a background job to create endpoint snapshots
          --snapshot-interval="5m"   Duration between each endpoint snapshot job
          --admin-password=ADMIN-PASSWORD  
                                     指定admin的password,是加密过后的,可以由htpasswd产生
          --admin-password-file=ADMIN-PASSWORD-FILE  
                                     如果怕泄密,可以把密码写在一个文件中,这个里面是原始密码
      -l, --hide-label=HIDE-LABEL ...  
                                     隐藏具有某些标签的容器,-l可以多次使用
          --logo=LOGO                使用你自己的logo
      -t, --templates=TEMPLATES      或者直接指定一个url
          --template-file="/templates.json"  
                                     使用你自己的模板文件,默认的莫办文件位置在/templates.json
    

        ps:关于admin密码,有的同学觉得cli和文件都不保险,则可以把密码设置在docker的secret中,如下:

    $ echo -n mypassword | docker secret create portainer-pass -
    $ docker service create 
      --name portainer 
      --secret portainer-pass 
      --publish 9000:9000 
      --replicas=1 
      --constraint 'node.role == manager' 
      --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock 
      portainer/portainer 
      --admin-password-file '/run/secrets/portainer-pass' 
      -H unix:///var/run/docker.sock

    模板

        portainer中可以自定义一些模板,然后在portainer中创建容器的时候使用这些模块快速的创建,模板是json格式的,包含一些必选项和可选项。

        Container template definition format

            样例

    {
      "type": 1,
      "title": "Nginx",
      "description": "High performance web server",
      "logo": "https://cloudinovasi.id/assets/img/logos/nginx.png",
      "image": "nginx:latest",
      "ports": [
        "8080:80/tcp",
        "443/tcp"
      ]
    }

            解释

    type	必选项,1表示container,2表示swarm stack,3表示compose stack
    title   必选项
    description		必选项
    image	必选项,该应用使用的docker镜像
    administrator_only	可选项,是否只有管理员可用模板
    name	可选项,该模板在管理界面中显示的名称
    log		可选项,自定义的logo
    registry	可选项,docker镜像的仓库,默认是Dockerhub 
    command		可选项,容器里面运行的命令,如果没有指定,则默认运行dockerfile的command
    network		可选项,模板使用的网络
    volumes		可选项,模板使用的volume
    ports    可选项,模板exposed的端口
    labels    可选项,模板上定义的labels
    privileged    可选项,容器是否能在超级权限启动
    interactive    可选项,容器启动时是否是交互模式,即添加-i -t
    restart_policy    可选项,容器的重启策略
    hostname    可选项,容器的主机名
    note    可选项,关于模板的信息
    platform    可选项,支持的平台,一般是linux或者windows
    categories    可选项,模板的类别,可以在UI上通过category来过滤


        Stack template definition format

            样例

    {
      "type": 2,
      "title": "CockroachDB",
      "description": "CockroachDB cluster",
      "note": "Deploys an insecure CockroachDB cluster, please refer to <a href="https://www.cockroachlabs.com/docs/stable/orchestrate-cockroachdb-with-docker-swarm.html" target="_blank">CockroachDB documentation</a> for production deployments.",
      "categories": ["database"],
      "platform": "linux",
      "logo": "https://cloudinovasi.id/assets/img/logos/cockroachdb.png",
      "repository": {
        "url": "https://github.com/portainer/templates",
        "stackfile": "stacks/cockroachdb/docker-stack.yml"
      }
    }

            解释

    type	必选项,1表示container,2表示swarm stack,3表示compose stack
    title   必选项
    description		必选项
    registry	可选项,docker镜像的仓库,默认是Dockerhub 
    administrator_only	可选项,是否只有管理员可用模板
    name	可选项,该模板在管理界面中显示的名称
    logo		可选项,自定义的logo
    env	     可选项,定义模板的变量
    note    可选项,关于模板的信息
    platform    可选项,支持的平台,一般是linux或者windows
    categories    可选项,模板的类别,可以在UI上通过category来过滤

     

  • 相关阅读:
    Java输入/输出
    JSP第二天 JavaBean加强
    JSP 第一天学习
    java集合
    Github配置SSH Keys
    Android Fragment学习笔记
    Android开源资源整理
    centos终端显示字母重叠
    好用的log查看工具log2console
    .NET 日期转换
  • 原文地址:https://www.cnblogs.com/surplus/p/11368008.html
Copyright © 2020-2023  润新知