Portainer 容器管理

 

Portainer 概述

[GitHub] https://github.com/portainer/portainer

[Doc] https://portainer.readthedocs.io/en/stable/

Portainer(基于 Go) 是一个轻量级的管理界面,可让您轻松管理 Docker 主机 或 Swarm 集群。

Portainer 的使用意图是简单部署。 它包含可以在任何 Docker 引擎上运行的单个容器(Docker for Linux 和 Docker for Windows)。

Portainer 允许您管理 Docker 容器、image、volume、network 等。 它与独立的 Docker 引擎和 Docker Swarm 兼容。

Limitations

Portainer 完全支持以下 Docker 版本:

Docker 1.10 到 Docker 17.03(包括集群模式)

Docker Swarm> = 1.2.3

对以下 Docker 版本的部分支持(某些功能可能不可用):

Docker 1.9

Demo

特性

镜像管理

网络管理

数据卷管理

应用模板:支持自定义 App template,例 Nginx、Redis 等

状态面板

可查看 Docker 主机的容器、镜像、volume、network(包括查看容器内部 IP)

容器状态监控:CPU、内存、网络利用率,每 7 秒刷新一次

容器运行时状态:启动命令、环境变量等

控制台:

Web UI 提供容器的 Console 界面

Logs:可实时查看容器运行日志

权限分配:针对 Endpoints(Docker 主机)分配权限

使用感受(纳入生态圈)

小而美,目前只支持 Docker 和 Swarm 集群的管理

基于 tcp 的连接方式,可在一台主机上,对所有 Docker 宿主机进行管理

对于 mesos + marathon 的 PaaS 平台来说,做为扩展项目相当不错

目前不支持 LDAP,一大遗憾 …

添加 endpoints

注意:

使用 docker-machine 部署 Docker engine 主机时,会为每一台主机生成服务器证书

因此,在使用 portainer 管理 Docker 主机,在添加 Endpoints 时,需要开启 TLS 认证,上传相关 docker-mahcine 部署主机(192.168.20.4)的证书和 key

TLS CA certificate:ca.pem

TLS certificate:cert.pem

TLS key:key.pem

1

2

3

4

5

6

7

8

[root@MM-SH1A-20-04 ~]# ls ~/.docker/machine/certs/ | xargs -n1

### 华丽的分隔线

---

ca-key.pem ### CA key 文件

ca.pem ### CA 证书

cert.pem ### docker-machine cert 文件

key.pem ### docker-machine key 文件

方式一:Web UI

方式二:JSON

endpoints json

启动 portainer 容器时,指定 --external-endpoints 参数

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

[

{

"Name": "MM-SH1A-20-02",

"URL": "tcp://192.168.20.2:2376"

"TLS": true,

"TLSCACert": "/certs/ca.pem",

"TLSCert": "/certs/cert.pem",

"TLSKey": "/certs/key.pem"

},

...

{

"Name": "MS-SH1A-20-08",

"URL": "tcp://192.168.20.8:2376"

"TLS": true,

"TLSCACert": "/certs/ca.pem",

"TLSCert": "/certs/cert.pem",

"TLSKey": "/certs/key.pem"

}

]

必填项:

Name:endpoint 节点名称,

URL:endpoint 地址,支持 tcp:// 和 unix://

可选项:

TLS:启用 TLS 认证

TLSCACert:CA 证书

TLSCert:连接 endpoint 的证书

TLSKey:连接 endpoint 的 key

启动 portainer 容器

portainer 命令

--host, -H: Docker daemon endpoint

--bind, -p: Address and port to serve Portainer (default: :9000)

--data, -d: Directory where Portainer data will be stored (default: /data on Linux, C:\data on Windows)

--tlsverify: TLS support (default: false)

--tlscacert: Path to the CA (default: /certs/ca.pem on Linux, C:\certs\ca.pem on Windows)

--tlscert: Path to the TLS certificate file (default: /certs/cert.pem, C:\certs\cert.pem on Windows)

--tlskey: Path to the TLS key (default: /certs/key.pem, C:\certs\key.pem on Windows)

--hide-label, -l: Hide containers with a specific label in the UI

--logo: URL to a picture to be displayed as a logo in the UI, use Portainer logo if not specified

--templates, -t: URL to templates (apps) definitions (default: https://raw.githubusercontent.com/portainer/templates/master/templates.json)

--no-analytics: Disable analytics (default: false)

--no-auth: Disable internal authentication mechanism (default: false)

--external-endpoints: Enable external endpoint management by specifying the path to a JSON endpoint source in a file

--sync-interval: Time interval between two endpoints synchronization requests expressed as a string, e.g. 30s, 5m, 1h… as supported by the time.ParseDuration method (default: 60s)

docker-compose.yml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

### portainer - Service define start

portainer:

image: registry.service/library/portainer:1.12.4

volumes:

- /var/run/docker.sock:/var/run/docker.sock

- /data/portainer:/data

- /data/portainer/certs:/certs

- /data/portainer/endpoints.json:/endpoints.json

ports:

- "3000:9000"

hostname: portainer

mem_limit: 1024M

restart: always

command: "--tlsverify --tlscacert /certs/ca.pem

--tlscert /certs/cert.pem

--tlskey /certs/key.pem

--logo http://p.i139.cn/p/c8999

--external-endpoints /endpoints.json"

### portainer - Service define end

创建 portainer 容器:

Docker endpoints 主机列表

Endpoints Dashboard

总览

容器面板

Stats:系统资源使用情况

Logs:容器运行日志

>_ Consule:容器控制台

系统资源

容器运行日志

容器 Console 控制台

隐藏指定的容器

Portainer 允许您使用 -l 选项隐藏具有特定标签的容器。

例如:指定某一容器运行的 label 为 owner=acme(请注意,这是一个示例标签,您可以定义自己的标签):

1

$ docker run -d --label owner=acme nginx

要隐藏此容器,只需在启动 Portainer 时在 CLI 上添加 -l owner = acme 选项:

1

$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer -l owner=acme

请注意,可以多次重复 -l 选项以指定多个标签:

1

$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer -l owner=acme -l service=secret

容器模板(App Templates)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[

{

"title": "Redis",

"description": "Open-source in-memory data structure store",

"logo": "https://cloudinovasi.id/assets/img/logos/redis.png",

"registry": "registry.service/base",

"image": "redis-3.2.6:1.0",

"ports": [

"6379/tcp"

],

"volumes": ["/data/databases/redis"],

"env": [

{

"name": "REDIS_PASS",

"label": "Redis password",

"type": "container",

"set": "redispass"

}

],

"command": "--auth --max-memory=2gb"

}

]

必填项:

title:模板标题

description:模板描述

logo:模板 logo

image:模板镜像,必须指定 tag

可选项

registry:镜像仓库地址

command:在容器中运行的命令。 如果未指定,容器将使用其 Dockerfile 中指定的默认命令

env:描述模板所需的环境变量的 JSON 数组, 数组中的每个元素都必须是有效的 JSON 对象

network:与现有 Docker 网络名称相对应的字符串

volumes:描述模板关联卷的 JSON 数组,数组中的每个元素都必须是一个有效的 JSON 字符串

ports:描述由模板公开的端口的 JSON 数组,数组中的每个元素必须是一个有效的 JSON 字符串,指定容器端口号和协议

privileged:布尔值,指定容器以特权模式启动。 如果未指定,则默认为 false

Nginx templates 容器

您可以构建自己的容器,使用 Nginx 来提供模板定义。可以克隆 Portainer 模板存储库,编辑模板文件,构建并运行容器。

Step 1:克隆 portainer-templates

1

# git clone https://github.com/portainer/templates.git portainer-templates

Step 2:自定义容器 App template

1

# cd portainer-templates

Edit the file templates.json:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[

{

"title": "Redis",

"description": "Open-source in-memory data structure store",

"logo": "https://cloudinovasi.id/assets/img/logos/redis.png",

"registry": "registry.service/base",

"image": "redis-3.2.6:1.0",

"ports": [

"6379/tcp"

],

"volumes": ["/data/databases/redis"],

"env": [

{

"name": "REDIS_PASS",

"label": "Redis password",

"type": "container",

"set": "redispass"

}

],

"command": "--auth --max-memory=2gb"

}

]

Step 3:build templates 镜像

1

# docker build -t registry.service/base/portainer-templates:1.0 .

Step 4:docker-compose.yml(portainer-templates )

1

2

3

4

5

6

7

8

9

10

11

### portainer-templates - Service define start

portainer-templates:

image: registry.service/base/portainer-templates:1.0

volumes:

- /data/portainer/templates.json:/usr/share/nginx/html/templates.json

ports:

- "3080:80"

hostname: portainer-templates

mem_limit: 128M

restart: always

### portainer-templates - Service define end

Step 5:创建 portainer-templates 容器

1

# docker-encap up -d portainer-templates

验证模板定义:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

# curl http://192.168.20.5:3080/templates.json

[

{

"title": "Redis",

"description": "Open-source in-memory data structure store",

"logo": "https://cloudinovasi.id/assets/img/logos/redis.png",

"registry": "registry.service/base",

"image": "redis-3.2.6:1.0",

"ports": [

"6379/tcp"

],

"volumes": ["/data/databases/redis"],

"env": [

{

"name": "REDIS_PASS",

"label": "Redis password",

"type": "container",

"set": "redispass"

}

],

"command": "--auth --max-memory=2gb"

}

]

重建 portainer 容器

更新 portainer docker-compose.yml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

### portainer - Service define start

portainer:

image: registry.service/library/portainer:1.12.4

volumes:

- /var/run/docker.sock:/var/run/docker.sock

- /data/portainer:/data

- /data/portainer/certs:/certs

- /data/portainer/endpoints.json:/endpoints.json

ports:

- "3000:9000"

hostname: portainer

mem_limit: 128M

restart: always

command: "--tlsverify --tlscacert /certs/ca.pem

--tlscert /certs/cert.pem

--tlskey /certs/key.pem

--external-endpoints /endpoints.json

--templates http://192.168.20.5:3080/templates.json"

### portainer - Service define end

--templates:指定容器 App templates

Web UI 验证(App Templates)

END

猜你喜欢

转载自blog.csdn.net/MatrixGod/article/details/81975812