direktori cari
Compose About versions and upgrading (Compose) ASP.NET Core + SQL Server on Linux (Compose) CLI environment variables (Compose) Command-line completion (Compose) Compose(组成) Compose command-line reference(组合命令行参考) Control startup order (Compose) Django and PostgreSQL (Compose) Docker stacks and distributed application bundles (Compose) docker-compose build(docker-compose构建) docker-compose bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .NET Core application (Engine) About images, containers, and storage drivers (Engine) Add nodes to the swarm (Engine) Apply custom metadata (Engine) Apply rolling updates (Engine) apt-cacher-ng Best practices for writing Dockerfiles (Engine) Binaries (Engine) Bind container ports to the host (Engine) Breaking changes (Engine) Build your own bridge (Engine) Configure container DNS (Engine) Configure container DNS in user-defined networks (Engine) CouchDB (Engine) Create a base image (Engine) Create a swarm (Engine) Customize the docker0 bridge (Engine) Debian (Engine) Default bridge network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (Engine) Fedora (Engine) Get started (Engine) Get started with macvlan network driver (Engine) Get started with multi-host networking (Engine) How nodes work (Engine) How services work (Engine) Image management (Engine) Inspect the service (Engine) Install Docker (Engine) IPv6 with Docker (Engine) Join nodes to a swarm (Engine) Legacy container links (Engine) Lock your swarm (Engine) Manage nodes in a swarm (Engine) Manage sensitive data with Docker secrets (Engine) Manage swarm security with PKI (Engine) Manage swarm service networks (Engine) Migrate to Engine 1.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale the service (Engine) SDKs (Engine) Select a storage driver (Engine) Set up for the tutorial (Engine) SSHd (Engine) Storage driver overview (Engine) Store service configuration data (Engine) Swarm administration guide (Engine) Swarm mode key concepts (Engine) Swarm mode overlay network security model (Engine) Swarm mode overview (Engine) Understand container communication (Engine) Use multi-stage builds (Engine) Use swarm mode routing mesh (Engine) Use the AUFS storage driver (Engine) Use the Btrfs storage driver (Engine) Use the Device mapper storage driver (Engine) Use the OverlayFS storage driver (Engine) Use the VFS storage driver (Engine) Use the ZFS storage driver (Engine) Engine: Admin Guide Amazon CloudWatch logs logging driver (Engine) Bind mounts (Engine) Collect Docker metrics with Prometheus (Engine) Configuring and running Docker (Engine) Configuring logging drivers (Engine) Control and configure Docker with systemd (Engine) ETW logging driver (Engine) Fluentd logging driver (Engine) Format command and log output (Engine) Google Cloud logging driver (Engine) Graylog Extended Format (GELF) logging driver (Engine) Journald logging driver (Engine) JSON File logging driver (Engine) Keep containers alive during daemon downtime (Engine) Limit a container's resources (Engine) Link via an ambassador container (Engine) Log tags for logging driver (Engine) Logentries logging driver (Engine) PowerShell DSC usage (Engine) Prune unused Docker objects (Engine) Run multiple services in a container (Engine) Runtime metrics (Engine) Splunk logging driver (Engine) Start containers automatically (Engine) Storage overview (Engine) Syslog logging driver (Engine) tmpfs mounts Troubleshoot volume problems (Engine) Use a logging driver plugin (Engine) Using Ansible (Engine) Using Chef (Engine) Using Puppet (Engine) View a container's logs (Engine) Volumes (Engine) Engine: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor security profiles for Docker (Engine) Automation with content trust (Engine) Content trust in Docker (Engine) Delegations for content trust (Engine) Deploying Notary (Engine) Docker security (Engine) Docker security non-events (Engine) Isolate containers with a user namespace (Engine) Manage keys for content trust (Engine) Play in a content trust sandbox (Engine) Protect the Docker daemon socket (Engine) Seccomp security profiles for Docker (Engine) Secure Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver options and operating system defaults (Machine) Drivers overview (Machine) Exoscale (Machine) Generic (Machine) Get started with a local VM (Machine) Google Compute Engine (Machine) IBM Softlayer (Machine) Install Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (Machine) Oracle VirtualBox (Machine) Provision AWS EC2 instances (Machine) Provision Digital Ocean Droplets (Machine) Provision hosts in the cloud (Machine) Rackspace (Machine) VMware Fusion (Machine) VMware vCloud Air (Machine) VMware vSphere (Machine) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server configuration (Notary) Signer configuration (Notary) Understand the service architecture (Notary) Use the Notary client
watak

Docker 引擎管理的插件系统

  • 安装和使用插件

  • 开发一个插件

  • 调试插件

Docker Engine 的插件系统允许您使用 Docker Engine 安装,启动,停止和移除插件。

有关 Docker Engine 1.12及更早版本中提供的传统插件系统的信息,请参阅了解传统 Docker 引擎插件。

注意:Windows 守护程序目前不支持 Docker Engine 托管插件。

安装和使用插件

插件以 Docker 镜像的形式发布,可以托管在 Docker Hub 或私有注册表中。

要安装插件,请使用docker plugin install从 Docker Hub 或您的私人注册表中提取插件的命令,并在必要时提示您授予权限或功能,并启用该插件。

要检查已安装插件的状态,请使用该docker plugin ls命令。成功启动的插件在输出中列为启用。

在安装插件之后,您可以将其用作另一个 Docker 操作的选项,例如创建卷。

在以下示例中,您将安装sshfs插件,验证它是否已启用,并使用它来创建卷。

注意:本示例仅用于说明目的。创建卷后,在检查卷时,远程主机的SSH密码将作为纯文本公开。您应该在完成示例后立即删除该卷。

  1. 安装sshfs插件。$ docker 插件安装 vieux / sshfs 插件“vieux / sshfs”正在请求以下权限: -  network:host  -  capabilities:CAP_SYS_ADMIN 您是否授予上述权限?y / N y vieux / sshfs 该插件请求2个权限:

- It needs access to the `host` network.- It needs the `CAP_SYS_ADMIN` capability, which allows the plugin to run the `mount` command.
  1. 检查插件是否在输出中启用docker plugin ls。$ docker plugin ls ID名称标签说明已启用69553ca1d789 vieux / sshfs最新sshfs插件true

  2. 使用插件创建一个卷。本示例将/remote主机上的目录挂载1.2.3.4到名为的卷中sshvolume。该卷现在可以安装到容器中。$ docker volume create \ -d vieux / sshfs \ --name sshvolume \ -o sshcmd=user@1.2.3.4:/ remote \ -o password = $(cat file_containing_password_for_remote_host)sshvolume

  3. 确认卷已成功创建。$ docker卷ls DRIVER名称vieux / sshfs sshvolume

  4. 启动一个使用该卷的容器sshvolume。$ docker run --rm -v sshvolume:/ data busybox ls / data <机器上的/ remote的内容1.2.3.4>

  5. 删除卷sshvolume docker卷rm sshvolume sshvolume要禁用某个插件,请使用该docker plugin disable命令。要完全删除它,请使用该docker plugin remove命令。有关其他可用的命令和选项,请参阅命令行参考。

开发一个插件

rootfs 目录

rootfs目录代表插件的根文件系统。在这个例子中,它是从 Dockerfile 创建的:

注意:/run/docker/plugins目录在插件的文件系统内部用于 docker 与插件进行通信。

$ git clone https://github.com/vieux/docker-volume-sshfs
$ cd docker-volume-sshfs
$ docker build -t rootfsimage .$ id=$(docker create rootfsimage true) # id was cd851ce43a403 when the image was created
$ sudo mkdir -p myplugin/rootfs
$ sudo docker export "$id" | sudo tar -x -C myplugin/rootfs
$ docker rm -vf "$id"$ docker rmi rootfsimage

config.json 文件

config.json文件描述了该插件。请参阅插件配置参考。

考虑下面的config.json文件。

{"description": "sshFS plugin for Docker","documentation": "https://docs.docker.com/engine/extend/plugins/","entrypoint": ["/docker-volume-sshfs"],"network": {   "type": "host"   },"interface" : {   "types": ["docker.volumedriver/1.0"],   "socket": "sshfs.sock"},"linux": {"capabilities": ["CAP_SYS_ADMIN"]}}

这个插件是一个音量驱动程序。它需要一个host网络和CAP_SYS_ADMIN能力。它取决于/docker-volume-sshfs入口点并使用/run/docker/plugins/sshfs.sock套接字与Docker引擎进行通信。这个插件没有运行时参数。

创建插件

通过运行docker plugin create <plugin-name> ./path/to/plugin/data插件数据包含插件配置文件config.json和子目录中的根文件系统,可以创建一个新的插件rootfs

之后,插件<plugin-name>将显示在docker plugin ls。可以使用插件将插件推送到远程注册表docker plugin push <plugin-name>

调试插件

插件的 stdout 被重定向到 dockerd 日志。这些条目有一个plugin=<ID>后缀。以下是docker f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62守护程序日志中 pluginID 及其相应日志条目的几个命令示例。

$ docker plugin install tiborvass/sample-volume-plugins

INFO[0036] Starting...       Found 0 volumes on startup  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
$ docker volume create -d tiborvass/sample-volume-plugins samplevol

INFO[0193] Create Called...  Ensuring directory /data/samplevol exists on host...  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0193] open /var/lib/docker/plugin-data/local-persist.json: no such file or directory  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0193]                   Created volume samplevol with mountpoint /data/samplevol  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0193] Path Called...    Returned path /data/samplevol  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
$ docker run -v samplevol:/tmp busybox sh

INFO[0421] Get Called...     Found samplevol                plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0421] Mount Called...   Mounted samplevol              plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0421] Path Called...    Returned path /data/samplevol  plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62
INFO[0421] Unmount Called... Unmounted samplevol            plugin=f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62

使用 docker-runc 将日志文件和 shell 获取到插件中。

docker-runc,默认的 docker 容器运行时可用于调试插件。如果插件日志被重定向到文件,这特别有用。

$ docker-runc list
ID                                                                 PID         STATUS      BUNDLE                                                                                       CREATED
f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62   2679        running     /run/docker/libcontainerd/f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff622017-02-06T21:53:03.031537592Z
r
$ docker-runc exec f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62 cat /var/log/plugin.log

如果插件具有内置的 shell,那么可以按照如下方式执行插件:

$ docker-runc exec -t f52a3df433b9aceee436eaada0752f5797aab1de47e5485f1690a073b860ff62 sh

使用 curl 调试插件套接字问题。

要验证 docker 守护程序与之通信的插件 API 套接字是否响应,请使用 curl。在本例中,我们将使用 curl 7.47.0 从 docker 主机到卷和网络插件进行 API 调用,以确保插件正在侦听所述套接字。对于运行良好的插件,这些基本要求应该可以工作。请注意,插件套接字在主机下可用/var/run/docker/plugins/<pluginID>

curl -H "Content-Type: application/json" -XPOST -d '{}' --unix-socket /var/run/docker/plugins/e8a37ba56fc879c991f7d7921901723c64df6b42b87e6a0b055771ecf8477a6d/plugin.sock http:/VolumeDriver.List{"Mountpoint":"","Err":"","Volumes":[{"Name":"myvol1","Mountpoint":"/data/myvol1"},{"Name":"myvol2","Mountpoint":"/data/myvol2"}],"Volume":null}
curl -H "Content-Type: application/json" -XPOST -d '{}' --unix-socket /var/run/docker/plugins/45e00a7ce6185d6e365904c8bcf62eb724b1fe307e0d4e7ecc9f6c1eb7bcdb70/plugin.sock http:/NetworkDriver.GetCapabilities{"Scope":"local"}

当使用 curl 7.5或更高版本时,URL应该是表单的形式http://hostname/APICall,其中hostname是安装插件的有效主机名,并且APICall是对插件 API 的调用。

例如, http://localhost/VolumeDriver.List

Artikel sebelumnya: Artikel seterusnya: