目录搜索
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
文字

注意:您可能已被重定向到此页面,因为您的 Linux 发行版不再有动态链接的 Docker 软件包。

如果你想尝试 Docker 或者在测试环境中使用它,但你不在受支持的平台上,你可以尝试从静态二进制文件安装。如果可能,应该使用为您的操作系统构建的软件包,并使用操作系统的软件包管理系统来管理 Docker 安装和升级。请注意,32位静态二进制归档文件不包含 Docker 守护进程(daemon)。

Docker 守护进程(daemon)二进制文件的静态二进制文件仅适用于 Linux(as dockerd)和 Windows Server 2016 或 Windows 10(as dockerd.exe)。Docker 客户端的静态二进制文件可用于 Linux 和 MacOS(as docker)以及 Windows Server 2016或 Windows 10(as docker.exe)。

在 Linux 上安装守护进程和客户端二进制文件

先决条件

本文档涵盖Docker公司和Docker社区推荐的最佳做法和方法,以创建易于使用、有效的产品。Dockerfile我们强烈建议您遵循这些建议%28事实上,如果您正在创建一个官方形象,您坚持这些实践%29。

  • 64位安装

注意:有关此处提到的任何Dockerfile命令的更详细说明,请访问Dockerfile引用一页。

  • iptables 版本1.4或更高

  • git 版本1.7或更高版本

由图像生成的容器Dockerfile定义应该尽可能的短暂。所谓“短暂”,我们的意思是,它可以被停止和摧毁,一个新的建立和安置的绝对最小的设置和配置。您可能想看看过程12要素应用程序方法中的一节,以了解以这样一种无状态方式运行容器的动机。

  • XZ Utils  4.9或更高版本

在大多数情况下,最好将每个Dockerfile放在一个空目录中。然后,只向该目录添加构建Dockerfile所需的文件。若要提高生成的性能,可以通过添加.dockerignore文件也放在那个目录下。此文件支持类似于.gitignore档案。有关创建一个的信息,请参见.dockerignore文件...

避免安装不必要的软件包

为了减少复杂性、依赖性、文件大小和构建时间,您应该避免仅仅因为“拥有”额外的或不必要的包而安装它们。例如,不需要在数据库映像中包含文本编辑器。

每个容器应该只关心一个问题。

将应用程序解耦到多个容器中,可以更容易地进行水平扩展和重用容器。例如,Web应用程序堆栈可能由三个单独的容器组成,每个容器都有自己独特的映像,以解耦的方式管理Web应用程序、数据库和内存中的缓存。

您可能听说过“每个容器应该有一个过程”。虽然这个咒语有良好的意图,但不一定每个容器只应该有一个操作系统进程。除了容器现在可以由init进程生成,一些程序可能会自动产生额外的进程。例如,芹菜可以生成多个工作进程,或阿帕奇可能会为每个请求创建一个进程。虽然“每个容器一个进程”通常是一个好的经验法则,但它并不是一个硬和快速的规则。用你最好的判断来保持容器尽可能的干净和模块化。

如果容器相互依赖,则可以使用码头集装箱网络以确保这些容器能够通信。

尽量减少层数

您需要找到可读性(以及长期可维护性)Dockerfile与最小化其使用的层数之间的平衡。对您使用的图层数量保持战略性和谨慎。

排序多行参数

只要有可能,可以通过对多行参数进行字母数字排序来简化以后的更改。这将帮助您避免包的重复,并使列表更容易更新。这也使PRs更容易阅读和审查。在反斜杠%28之前添加空格\%29也有帮助。

下面是一个来自buildpack-deps图像*

RUN apt-get update && apt-get install -y \
  bzr \
  cvs \
  git \
  mercurial \
  subversion

构建缓存

在构建图像码头的过程中,您将逐步了解Dockerfile按照指定的顺序执行每个。在检查每条指令时,Docker将在其缓存中寻找一个可以重用的现有映像,而不是创建一个新的%28重复%29映像。如果您根本不想使用缓存,则可以使用--no-cache=true选项的docker build命令。

但是,如果您确实让Docker使用它的缓存,那么非常重要的是要了解它什么时候会,并且不会找到匹配的映像。码头工人将遵循的基本规则概述如下:

  • 从缓存中已经存在的父映像开始,将下一条指令与从该基本映像派生的所有子映像进行比较,以查看其中一个是使用完全相同的指令生成的。否则,缓存将失效。

  • 在大多数情况下,只需比较Dockerfile其中一个孩子的图像就足够了。然而,某些指示需要更多的检查和解释。

  • ADDCOPY说明,检查图像中文件%28s%29的内容,并计算每个文件的校验和。在这些校验和中不考虑文件%28s%29的最后修改和最后访问次数。在缓存查找过程中,将校验和与现有图像中的校验和进行比较。如果文件%28s%29中有任何更改,如内容和元数据,则缓存无效。

  • 除了ADDCOPY命令时,缓存检查将不会查看容器中的文件以确定缓存匹配。例如,当处理RUN apt-get -y update命令不会检查容器中更新的文件以确定是否存在缓存命中。在这种情况下,仅使用命令字符串本身来查找匹配项。

一旦缓存失效,所有后续Dockerfile命令将生成新图像,缓存将不被使用。

Dockerfile指令

下面,您将找到关于编写各种可用说明的最佳方法的建议,以便在Dockerfile...

FROM指令的Dockerfile引用

只要有可能,使用当前的官方存储库作为你形象的基础。我们推荐Debian图像因为它是非常严格控制和保持最小的%28目前低于150 MB%29,同时仍然是一个完整的发行版。

标签

理解对象标签

您可以向图像中添加标签,以帮助按项目组织图像、记录许可信息、帮助自动化或其他原因。对于每个标签,添加一行以LABEL和一个或多个键值对。下面的示例显示了不同的可接受格式。解释性评论包括内联。

*如果字符串包含空格,则必须引用它这些空间必须逃掉。如果字符串包含内部引号字符%28"%29,也要逃离他们。

# Set one or more individual labels
LABEL com.example.version="0.0.1-beta"LABEL vendor="ACME Incorporated"LABEL com.example.release-date="2015-02-12"LABEL com.example.version.is-production=""# Set multiple labels on one line
LABEL com.example.version="0.0.1-beta" com.example.release-date="2015-02-12"# Set multiple labels at once, using line-continuation characters to break long lines
LABEL vendor=ACME\ Incorporated \
      com.example.is-beta= \
      com.example.is-production="" \
      com.example.version="0.0.1-beta" \
      com.example.release-date="2015-02-12"

见理解对象标签有关可接受的标签键和值的指南。有关查询标签的信息,请参考与管理对象的标签...

运行指令的Dockerfile引用

一如既往,让你Dockerfile更易读,更易理解,更易维护,分裂更长或更复杂RUN语句在用反斜杠分隔的多行上。

上一篇:下一篇: