目錄 搜尋
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
文字

在成功安装 Docker 并启动 Docker 之后,dockerd守护进程将以其默认配置运行。本主题将介绍如何自定义配置,手动启动守护程序以及如果遇到问题时对守护程序进行故障排除和调试。

使用操作系统实用程序启动守护进程(daemon

启动 Docker 的命令取决于您的操作系统。检查安装 Docker 下的正确页面。要将 Docker 配置为在系统引导时自动启动,请参阅将 Docker 配置为在引导时启动。

手动启动守护程序(daemon

通常,您使用操作系统实用程序启动 Docker。出于调试目的,您可以使用该dockerd命令手动启动 Docker 。您可能需要使用sudo,具体取决于您的操作系统配置。当您以这种方式启动 Docker 时,它会在前台运行,并将其日志直接发送到您的终端。

$ dockerd

INFO[0000] +job init_networkdriver()INFO[0000] +job serveapi(unix:///var/run/docker.sock)INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)......

要在您手动启动 Docker 时停止 Docker,请在您的终端中发出一个Ctrl+C

配置 Docker 守护进程

守护进程(daemon)包含许多配置选项,您可以在手动启动 Docker 时将其作为标志传递,或者在daemon.json配置文件中进行设置。推荐使用第二种方法,因为重新启动 Docker 时,这些配置更改仍然存在。

请参阅 dockerd 以获取完整的配置选项列表。

以下是使用一些配置选项手动启动 Docker 守护程序(daemon)的示例:

$ dockerd -D --tls=true --tlscert=/var/docker/server.pem --tlskey=/var/docker/serverkey.pem -H tcp://192.168.59.3:2376

此命令启用 debugging(-D),启用 TLS(-tls),指定服务器证书和密钥(--tlscert--tlskey),并指定守护程序侦听连接的网络接口(-H)。

更好的方法是将这些选项放入daemon.json文件并重新启动 Docker。此方法适用于每个 Docker 平台。以下daemon.json示例设置与上述命令相同的所有选项:

{  "debug": true,  "tls": true,  "tlscert": "/var/docker/server.pem",  "tlskey": "/var/docker/serverkey.pem",  "hosts": ["tcp://192.168.59.3:2376"]}

Docker 文档中会讨论许多特定的配置选项。接下来的一些地方包括:

  • 自动启动容器

  • 限制容器的资源

  • 配置存储驱动程序

  • 容器安全

排除守护进程(daemon)故障

您可以在守护进程上启用调试,以了解守护进程的运行时活动并帮助进行故障排除。如果守护进程完全没有响应,您还可以通过向 Docker 守护进程(daemon)发送SIGUSR信号来强制将所有线程的完整堆栈跟踪添加到守护进程日志中。

内存异常(OOME)

如果您的容器尝试使用比系统可用的内存更多的内存,则可能会遇到内存异常(OOME),并且容器或 Docker 守护程序(daemon)可能会被内核 OOM 切断器所切断。要防止发生这种情况,请确保您的应用程序在具有足够内存的主机上运行,并且请参阅了解耗尽内存的风险。

阅读日志

守护进程(daemon)日志可以帮助您诊断问题。根据操作系统配置和使用的日志记录子系统,日志可以保存在几个位置之一中:

操作系统

位置

RHEL, Oracle Linux

/var/log/messages

Debian

/var/log/daemon.log

Ubuntu 16.04+, CentOS

Use the command journalctl -u docker.service

Ubuntu 14.10-

/var/log/upstart/docker.log

macOS

~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/console-ring

Windows

AppData\Local

启用调试

有两种方法来启用调试。推荐的方法是将debug密钥设置truedaemon.json文件中。此方法适用于每个 Docker 平台。

1. 编辑daemon.json通常位于/etc/docker/的文件。如果该文件尚不存在,您可能需要创建该文件。在 macOS 或 Windows 上,请勿直接编辑文件。相反,请转到首选项 / 守护进程 / 高级

2. 如果文件为空,请添加以下内容:

{   "debug": true }

如果该文件已经包含 JSON,只需添加该键"debug": true,如果它不是结束括号之前的最后一行,请注意在该行的末尾添加逗号。同时验证是否log-level已设置密钥,将其设置为infodebuginfo是默认的,和可能的值是debuginfowarnerrorfatal

3. HUP向守护程序发送信号以使其重新加载其配置。在 Linux 主机上,使用以下命令。

$ sudo kill -SIGHUP $(pidof dockerd)

在 Windows 主机上,重新启动 Docker。您可以停止 Docker 守护进程并使用该-D标志手动重新启动它。但是,这可能会导致 Docker 以与主机的启动脚本创建的环境不同的环境重新启动,并且这可能会使调试更加困难。强制要记录的堆栈跟踪如果守护进程没有响应,可以强制执行完整的堆栈跟踪通过向SIGUSR1守护进程发送信号进行记录。

  • Linux

$ sudo kill -SIGUSR1 $(pidof dockerd)

  • Windows 服务器

下载 docker-signal。

--pid=<PID of daemon>标志运行可执行文件。

这将强制堆栈跟踪被记录,但不会停止守护进程(Daemon)。如果守护进程日志记录到文件中,它将显示堆栈跟踪或包含堆栈跟踪的文件的路径。

守护进程(Daemon)将在处理完SIGUSR1信号并将堆栈跟踪转储到日志后继续运行。堆栈跟踪可用于确定守护进程内所有 goroutine 和线程的状态。

检查 Docker 是否正在运行

检查 Docker 是否运行的操作系统无关的方法是使用该docker info命令询问 Docker 。

您还可以使用操作系统实用程序(例如sudo systemctl is-active dockersudo status dockersudo service docker status),或者使用 Windows 实用程序检查服务状态。

最后,您可以dockerd使用类似于pstop的命令检入进程的进程列表。

上一篇: 下一篇: