目录搜索
ComposeAbout 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 bundledocker-compose configdocker-compose createdocker-compose downdocker-compose eventsdocker-compose execdocker-compose helpdocker-compose imagesdocker-compose killdocker-compose logsdocker-compose pausedocker-compose portdocker-compose psdocker-compose pulldocker-compose pushdocker-compose restartdocker-compose rmdocker-compose rundocker-compose scaledocker-compose startdocker-compose stopdocker-compose topdocker-compose unpausedocker-compose upEnvironment file (Compose)Environment variables in ComposeExtend services in ComposeFrequently asked questions (Compose)Getting started (Compose)Install ComposeLink environment variables (deprecated) (Compose)Networking in ComposeOverview of Docker ComposeOverview of docker-compose CLIQuickstart: Compose and WordPressRails and PostgreSQL (Compose)Sample apps with ComposeUsing Compose in productionUsing Compose with SwarmEngine.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-ngBest 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 networkDelete the service (Engine)Deploy a service (Engine)Deploy services to a swarm (Engine)Deprecated Engine featuresDocker container networking (Engine)Docker overview (Engine)Docker run reference (Engine)Dockerfile reference (Engine)Dockerize an applicationDrain a node (Engine)EngineFAQ (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.10Optional Linux post-installation steps (Engine)Overview (Engine)PostgreSQL (Engine)Raft consensus in swarm mode (Engine)Riak (Engine)Run Docker Engine in swarm modeScale 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 GuideAmazon 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 mountsTroubleshoot 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: CLIDaemon CLI reference (dockerd) (Engine)dockerdocker attachdocker builddocker checkpointdocker checkpoint createdocker checkpoint lsdocker checkpoint rmdocker commitdocker configdocker config createdocker config inspectdocker config lsdocker config rmdocker containerdocker container attachdocker container commitdocker container cpdocker container createdocker container diffdocker container execdocker container exportdocker container inspectdocker container killdocker container logsdocker container lsdocker container pausedocker container portdocker container prunedocker container renamedocker container restartdocker container rmdocker container rundocker container startdocker container statsdocker container stopdocker container topdocker container unpausedocker container updatedocker container waitdocker cpdocker createdocker deploydocker diffdocker eventsdocker execdocker exportdocker historydocker imagedocker image builddocker image historydocker image importdocker image inspectdocker image loaddocker image lsdocker image prunedocker image pulldocker image pushdocker image rmdocker image savedocker image tagdocker imagesdocker importdocker infodocker inspectdocker killdocker loaddocker logindocker logoutdocker logsdocker networkdocker network connectdocker network createdocker network disconnectdocker network inspectdocker network lsdocker network prunedocker network rmdocker nodedocker node demotedocker node inspectdocker node lsdocker node promotedocker node psdocker node rmdocker node updatedocker pausedocker plugindocker plugin createdocker plugin disabledocker plugin enabledocker plugin inspectdocker plugin installdocker plugin lsdocker plugin pushdocker plugin rmdocker plugin setdocker plugin upgradedocker portdocker psdocker pulldocker pushdocker renamedocker restartdocker rmdocker rmidocker rundocker savedocker searchdocker secretdocker secret createdocker secret inspectdocker secret lsdocker secret rmdocker servicedocker service createdocker service inspectdocker service logsdocker service lsdocker service psdocker service rmdocker service scaledocker service updatedocker stackdocker stack deploydocker stack lsdocker stack psdocker stack rmdocker stack servicesdocker startdocker statsdocker stopdocker swarmdocker swarm cadocker swarm initdocker swarm joindocker swarm join-tokendocker swarm leavedocker swarm unlockdocker swarm unlock-keydocker swarm updatedocker systemdocker system dfdocker system eventsdocker system infodocker system prunedocker tagdocker topdocker unpausedocker updatedocker versiondocker volumedocker volume createdocker volume inspectdocker volume lsdocker volume prunedocker volume rmdocker waitUse the Docker command line (Engine)Engine: ExtendAccess authorization plugin (Engine)Docker log driver pluginsDocker network driver plugins (Engine)Extending Engine with pluginsManaged plugin system (Engine)Plugin configuration (Engine)Plugins API (Engine)Volume plugins (Engine)Engine: SecurityAppArmor 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 EngineUse trusted imagesUsing certificates for repository client verification (Engine)Engine: TutorialsEngine tutorialsNetwork containers (Engine)Get StartedPart 1: OrientationPart 2: ContainersPart 3: ServicesPart 4: SwarmsPart 5: StacksPart 6: Deploy your appMachineAmazon Web Services (Machine)Digital Ocean (Machine)docker-machine activedocker-machine configdocker-machine createdocker-machine envdocker-machine helpdocker-machine inspectdocker-machine ipdocker-machine killdocker-machine lsdocker-machine provisiondocker-machine regenerate-certsdocker-machine restartdocker-machine rmdocker-machine scpdocker-machine sshdocker-machine startdocker-machine statusdocker-machine stopdocker-machine upgradedocker-machine urlDriver 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 MachineMachineMachine CLI overviewMachine command-line completionMachine concepts and helpMachine overviewMicrosoft Azure (Machine)Microsoft Hyper-V (Machine)Migrate from Boot2Docker to MachineOpenStack (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)NotaryClient configuration (Notary)Common Server and signer configurations (Notary)Getting started with NotaryNotary changelogNotary configuration filesRunning a Notary serviceServer 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的命令检入进程的进程列表。

上一篇:下一篇: