diff --git a/engine/install/centos.md b/engine/install/centos.md index bbef40c..f374a7d 100644 --- a/engine/install/centos.md +++ b/engine/install/centos.md @@ -47,35 +47,28 @@ $ sudo yum remove docker \ Docker 引擎(Docker Engine)的包,当前被修改称为 `docker-ce`。 -## Installation methods +## 安装方法 -You can install Docker Engine in different ways, depending on your needs: +基于你的需求,你可以使用不同的方法安装 Docker 引擎(Docker Engine): -- Most users - [set up Docker's repositories](#install-using-the-repository) and install - from them, for ease of installation and upgrade tasks. This is the - recommended approach. +- 绝大部分用户使用 + [设置 Docker 的仓库](#install-using-the-repository) ,然后从设置成功后的仓库进行安装。为了更加容易进行安装和升级任务,Docker 的官方推荐使用这种安装方式来进行安装。 -- Some users download the RPM package and - [install it manually](#install-from-a-package) and manage - upgrades completely manually. This is useful in situations such as installing - Docker on air-gapped systems with no access to the internet. +- 一些用户可以使用下载的 RPM 包 ,然后 + [手动进行安装](#install-from-a-package) 然后你需要手动来进行升级。这种方法主要针对一些系统不具有联网环境,你需要下载后进行安装。 -- In testing and development environments, some users choose to use automated - [convenience scripts](#install-using-the-convenience-script) to install Docker. +- 在一些测试和部署环境中,一些用户采用自动化脚本来安装 Docker,请访问链接: + [自动化安装脚本](#install-using-the-convenience-script) 来了解更多。 -### Install using the repository +### 使用仓库进行安装 -Before you install Docker Engine for the first time on a new host machine, you need -to set up the Docker repository. Afterward, you can install and update Docker -from the repository. +在你对新安装的机器安装 Docker 之前,你需要设置 Docker 仓库。当仓库设置好以后,你可以从设置的仓库中对 Docker 进行安装和更新。 #### Set up the repository {% assign download-url-base = "https://download.docker.com/linux/centos" %} -Install the `yum-utils` package (which provides the `yum-config-manager` -utility) and set up the **stable** repository. +安装 `yum-utils` 包(这个安装包将会提供 `yum-config-manager` 工具)然后设置 **稳定(stable**)的仓库。 ```bash $ sudo yum install -y yum-utils @@ -85,57 +78,49 @@ $ sudo yum-config-manager \ {{ download-url-base }}/docker-ce.repo ``` -> **Optional**: Enable the **nightly** or **test** repositories. +> **可选的**:启用 **晚间构建(nightly)** 或 **测试(test)** 仓库。 > -> These repositories are included in the `docker.repo` file above but are disabled -> by default. You can enable them alongside the stable repository. The following -> command enables the **nightly** repository. +> 上面的这些仓库包含有 `docker.repo` 文件,但是在默认情况下是禁用的。你可以和稳定版本仓库地址一样来启用它们。下面的内容显示的是启用 **晚间构建(nightly)**仓库的命令。 > > ```bash > $ sudo yum-config-manager --enable docker-ce-nightly > ``` > -> To enable the **test** channel, run the following command: +> 希望启用 **测试(test)**仓库,请使用下面的命令: > > ```bash > $ sudo yum-config-manager --enable docker-ce-test > ``` > -> You can disable the **nightly** or **test** repository by running the -> `yum-config-manager` command with the `--disable` flag. To re-enable it, use -> the `--enable` flag. The following command disables the **nightly** repository. +> 你可以通过运行 `yum-config-manager` 命令,并在命令后面添加 `--disable` 标记来禁用 **晚间构建(nightly)** 或 **测试(test)**仓库。 +> 下面的命令是表示禁用 **晚间构建(nightly)**仓库: > > ```bash > $ sudo yum-config-manager --disable docker-ce-nightly > ``` > -> [Learn about **nightly** and **test** channels](index.md). +> [了解更多有关**晚间构建(nightly)** 和 **测试(test)**的通道](index.md)。 -#### Install Docker Engine +#### 安装 Docker 引擎 -1. Install the _latest version_ of Docker Engine and containerd, or go to the next step to install a specific version: +1. 安装*最新版本*的 Docker 引擎和容器,或者使用后续的步骤来为安装的指定特定的版本: ```bash $ sudo yum install docker-ce docker-ce-cli containerd.io ``` - If prompted to accept the GPG key, verify that the fingerprint matches - `060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35`, and if so, accept it. + 如果按照的时候提示需要校验 GPG Key,请确定指纹与字符串 `060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35` 是吻合的,然后选择接受。 - > Got multiple Docker repositories? + > 获得了多个 Docker 的仓库? > - > If you have multiple Docker repositories enabled, installing - > or updating without specifying a version in the `yum install` or - > `yum update` command always installs the highest possible version, - > which may not be appropriate for your stability needs. + > 如果你有多个 Docker 仓库被启用了,在使用 `yum install` 或 `yum update` 命令对 Docker 进行安装和升级的时候,如果你没有指定版本, + > 那么上面的命令将会尝试使用最新的版本进行安装。这有可能导致安装的版本不是你需要的。 - Docker is installed but not started. The `docker` group is created, but no users are added to the group. + Docker 被安装了,但是没有启动。这是因为 `docker` 组已经被创建了,但是还没有用户添加到组中。 -2. To install a _specific version_ of Docker Engine, list the available versions - in the repo, then select and install: +2. 针对 Docker 的安装*指定版本*的 Docker 引擎(Docker Engine),列出给定仓库中可用的 Docker 版本,然后选择需要的版本来进行安装: - a. List and sort the versions available in your repo. This example sorts - results by version number, highest to lowest, and is truncated: + a. 分类列出你仓库中可用的 Docker 版本。下面的示例列出了通过版本好进行分类的结果,从高到低的分类: ```bash $ yum list docker-ce --showduplicates | sort -r @@ -146,45 +131,38 @@ $ sudo yum-config-manager \ docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable ``` - The list returned depends on which repositories are enabled, and is specific - to your version of CentOS (indicated by the `.el7` suffix in this example). + 上面的列表是基于你启用的仓库不同来指定你 CentOS 操作系统的版本(如上面所示,使用 `el7` 后缀来标记)。 - b. Install a specific version by its fully qualified package name, which is - the package name (`docker-ce`) plus the version string (2nd column) - starting at the first colon (`:`), up to the first hyphen, separated by - a hyphen (`-`). For example, `docker-ce-18.09.1`. + b. 通过提供完整的包的名字来安装指定的版本的 Docke 引擎。完整的路径包括有包的名字(`docker-ce`)并且加上第二列提供的版本字符串。 + 从第一个冒号(`:`)后的字符开始计算,截止于分隔符(`-`)之前的字符。 + 例如: `docker-ce-18.09.1`。 ```bash $ sudo yum install docker-ce- docker-ce-cli- containerd.io ``` - Docker is installed but not started. The `docker` group is created, but no users are added to the group. + Docker 被安装了,但是没有启动。这是因为 `docker` 组已经被创建了,但是还没有用户添加到组中。 -3. Start Docker. +3. 启动 Docker ```bash $ sudo systemctl start docker ``` -4. Verify that Docker Engine is installed correctly by running the `hello-world` - image. +4. 通过运行 `hello-world` 镜像(image)来确定 Docker 安装成功了。 ```bash $ sudo docker run hello-world ``` - This command downloads a test image and runs it in a container. When the - container runs, it prints an informational message and exits. + 这个命令将会下载一个测试镜像并且在容器中运行。如果容器是运行的话,这个命令将会打印出一些信息后退出。 -Docker Engine is installed and running. You need to use `sudo` to run Docker -commands. Continue to [Linux postinstall](linux-postinstall.md) to allow -non-privileged users to run Docker commands and for other optional configuration -steps. +Docker 引擎已经安装并且运行了,你需要使用 `sudo` 来运行 Docker 的命令。请继续阅读页面 [Linux 安装 Docker 的后续步骤](linux-postinstall.md) +中的内容来允许你操作系统中没有权限的用户来允许 Docker 命令和其他的一些配置选项。 -#### Upgrade Docker Engine +#### 升级 Docker 引擎 -To upgrade Docker Engine, follow the [installation instructions](#install-using-the-repository), -choosing the new version you want to install. +希望对 Docker 引擎进行申请,请按照 [使用仓库进行安装](#install-using-the-repository),步骤,来选择你希望安装的新版本。 ### Install from a package diff --git a/engine/install/index.md b/engine/install/index.md new file mode 100644 index 0000000..35cc299 --- /dev/null +++ b/engine/install/index.md @@ -0,0 +1,164 @@ +--- +title: Install Docker Engine +description: Lists the installation methods +keywords: docker, installation, install, Docker Engine, Docker Engine, docker editions, stable, edge +redirect_from: +- /engine/installation/linux/ +- /engine/installation/linux/frugalware/ +- /engine/installation/frugalware/ +- /engine/installation/linux/other/ +- /engine/installation/linux/archlinux/ +- /engine/installation/linux/cruxlinux/ +- /engine/installation/linux/gentoolinux/ +- /engine/installation/linux/docker-ce/ +- /engine/installation/linux/docker-ee/ +- /engine/installation/ +- /en/latest/installation/ +--- + + +## Supported platforms + +Docker Engine is available on a variety of [Linux platforms](#server), +[macOS](../../docker-for-mac/install.md) and [Windows 10](../../docker-for-windows/install.md) +through Docker Desktop, and as a [static binary installation](binaries.md). Find +your preferred operating system below. + +### Desktop + +{% assign yes = '![yes](/images/green-check.svg){: .inline style="height: 14px; margin: 0 auto"}' %} + +| Platform | x86_64 / amd64 | +|:------------------------------------------------------------------|:------------------------------------------------:| +| [Docker Desktop for Mac (macOS)](../../docker-for-mac/install.md) | [{{ yes }}](../../docker-for-mac/install.md) | +| [Docker Desktop for Windows](../../docker-for-windows/install.md) | [{{ yes }}](../../docker-for-windows/install.md) | + +### Server + +Docker provides `.deb` and `.rpm` packages from the following Linux distributions +and architectures: + +| Platform | x86_64 / amd64 | ARM | ARM64 / AARCH64 | +|:----------------------|:-----------------------|:-------------------------|:-----------------------| +| [CentOS](centos.md) | [{{ yes }}](centos.md) | | [{{ yes }}](centos.md) | +| [Debian](debian.md) | [{{ yes }}](debian.md) | [{{ yes }}](debian.md) | [{{ yes }}](debian.md) | +| [Fedora](fedora.md) | [{{ yes }}](fedora.md) | | [{{ yes }}](fedora.md) | +| [Raspbian](debian.md) | | [{{ yes }}](debian.md) | [{{ yes }}](debian.md) | +| [Ubuntu](ubuntu.md) | [{{ yes }}](ubuntu.md) | [{{ yes }}](ubuntu.md) | [{{ yes }}](ubuntu.md) | + +### Other Linux distributions + +> **Note** +> +> While the instructions below may work, Docker does not test or verify +> installation on derivatives. + +- Users of Debian derivatives such as "BunsenLabs Linux", "Kali Linux" or + "LMDE" (Debian-based Mint) should follow the installation instructions for + [Debian](debian.md), substituting the version of their distro for the + corresponding Debian release. Refer to the documentation of your distro to find + which Debian release corresponds with your derivative version. +- Likewise, users of Ubuntu derivatives such as "Kubuntu", "Lubuntu" or "Xubuntu" + should follow the installation instructions for [Ubuntu](ubuntu.md), + substituting the version of their distro for the corresponding Ubuntu release. + Refer to the documentation of your distro to find which Ubuntu release + corresponds with your derivative version. +- Some Linux distributions are providing a package of Docker Engine through their + package repositories. These packages are built and maintained by the Linux + distribution's package maintainers and may have differences in configuration + or built from modified source code. Docker is not involved in releasing these + packages and bugs or issues involving these packages should be reported in + your Linux distribution's issue tracker. + +Docker provides [binaries](binaries.md) for manual installation of Docker Engine. +These binaries are statically linked and can be used on any Linux distribution. + +## Release channels + +Docker Engine has three types of update channels, **stable**, **test**, +and **nightly**: + +* The **Stable** channel gives you latest releases for general availability. +* The **Test** channel gives pre-releases that are ready for testing before + general availability (GA). +* The **Nightly** channel gives you latest builds of work in progress for the + next major release. + +### Stable + +Year-month releases are made from a release branch diverged from the master +branch. The branch is created with format `.`, for example +`19.03`. The year-month name indicates the earliest possible calendar +month to expect the release to be generally available. All further patch +releases are performed from that branch. For example, once `v19.03.0` is +released, all subsequent patch releases are built from the `19.03` branch. + +### Test + +In preparation for a new year-month release, a branch is created from +the master branch with format `YY.mm` when the milestones desired by +Docker for the release have achieved feature-complete. Pre-releases +such as betas and release candidates are conducted from their respective release +branches. Patch releases and the corresponding pre-releases are performed +from within the corresponding release branch. + +### Nightly + +Nightly builds give you the latest builds of work in progress for the next major +release. They are created once per day from the master branch with the version +format: + + 0.0.0-YYYYmmddHHMMSS-abcdefabcdef + +where the time is the commit time in UTC and the final suffix is the prefix +of the commit hash, for example `0.0.0-20180720214833-f61e0f7`. + +These builds allow for testing from the latest code on the master branch. No +qualifications or guarantees are made for the nightly builds. + +## Support + +Docker Engine releases of a year-month branch are supported with patches as +needed for one month after the next year-month general availability release. + +This means bug reports and backports to release branches are assessed +until the end-of-life date. + +After the year-month branch has reached end-of-life, the branch may be +deleted from the repository. + +### Backporting + +Backports to the Docker products are prioritized by the Docker company. A +Docker employee or repository maintainer will endeavour to ensure sensible +bugfixes make it into _active_ releases. + +If there are important fixes that ought to be considered for backport to +active release branches, be sure to highlight this in the PR description +or by adding a comment to the PR. + +### Upgrade path + +Patch releases are always backward compatible with its year-month version. + +### Licensing + +Docker is licensed under the Apache License, Version 2.0. See +[LICENSE](https://github.com/moby/moby/blob/master/LICENSE) for the full +license text. + +## Reporting security issues + +The Docker maintainers take security seriously. If you discover a security +issue, please bring it to their attention right away! + +Please DO NOT file a public issue; instead send your report privately +to security@docker.com. + +Security reports are greatly appreciated, and Docker will publicly thank you +for it. + +## Get started + +After setting up Docker, you can learn the basics with +[Getting started with Docker](../../get-started/index.md). diff --git a/engine/install/linux-postinstall.md b/engine/install/linux-postinstall.md new file mode 100644 index 0000000..a38dcd1 --- /dev/null +++ b/engine/install/linux-postinstall.md @@ -0,0 +1,500 @@ +--- +description: Optional post-installation steps for Linux +keywords: Docker, Docker documentation, requirements, apt, installation, ubuntu, install, uninstall, upgrade, update +title: Post-installation steps for Linux +redirect_from: +- /engine/installation/linux/docker-ee/linux-postinstall/ +- /engine/installation/linux/linux-postinstall/ +- /install/linux/linux-postinstall/ +--- + +This section contains optional procedures for configuring Linux hosts to work +better with Docker. + +## Manage Docker as a non-root user + +The Docker daemon binds to a Unix socket instead of a TCP port. By default +that Unix socket is owned by the user `root` and other users can only access it +using `sudo`. The Docker daemon always runs as the `root` user. + +If you don't want to preface the `docker` command with `sudo`, create a Unix +group called `docker` and add users to it. When the Docker daemon starts, it +creates a Unix socket accessible by members of the `docker` group. + +> Warning +> +> The `docker` group grants privileges equivalent to the `root` +> user. For details on how this impacts security in your system, see +> [*Docker Daemon Attack Surface*](../security/index.md#docker-daemon-attack-surface). +{: .warning} + +> **Note**: +> +> To run Docker without root privileges, see +> [Run the Docker daemon as a non-root user (Rootless mode)](../security/rootless.md). +> +> Rootless mode is currently available as an experimental feature. + +To create the `docker` group and add your user: + +1. Create the `docker` group. + + ```bash + $ sudo groupadd docker + ``` + +2. Add your user to the `docker` group. + + ```bash + $ sudo usermod -aG docker $USER + ``` + +3. Log out and log back in so that your group membership is re-evaluated. + + If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. + + On a desktop Linux environment such as X Windows, log out of your session completely and then log back in. + + On Linux, you can also run the following command to activate the changes to groups: + + ```bash + $ newgrp docker + ``` + +4. Verify that you can run `docker` commands without `sudo`. + + ```bash + $ docker run hello-world + ``` + + This command downloads a test image and runs it in a container. When the + container runs, it prints an informational message and exits. + + If you initially ran Docker CLI commands using `sudo` before adding + your user to the `docker` group, you may see the following error, + which indicates that your `~/.docker/` directory was created with + incorrect permissions due to the `sudo` commands. + + ```none + WARNING: Error loading config file: /home/user/.docker/config.json - + stat /home/user/.docker/config.json: permission denied + ``` + + To fix this problem, either remove the `~/.docker/` directory + (it is recreated automatically, but any custom settings + are lost), or change its ownership and permissions using the + following commands: + + ```bash + $ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R + $ sudo chmod g+rwx "$HOME/.docker" -R + ``` + +## Configure Docker to start on boot + +Most current Linux distributions (RHEL, CentOS, Fedora, Ubuntu 16.04 and higher) +use [`systemd`](#systemd) to manage which services start when the system boots. +Ubuntu 14.10 and below use [`upstart`](#upstart). + +### `systemd` + +```bash +$ sudo systemctl enable docker +``` + +To disable this behavior, use `disable` instead. + +```bash +$ sudo systemctl disable docker +``` + +If you need to add an HTTP Proxy, set a different directory or partition for the +Docker runtime files, or make other customizations, see +[customize your systemd Docker daemon options](../../config/daemon/systemd.md). + +### `upstart` + +Docker is automatically configured to start on boot using +`upstart`. To disable this behavior, use the following command: + +```bash +$ echo manual | sudo tee /etc/init/docker.override +``` + +### `chkconfig` + +```bash +$ sudo chkconfig docker on +``` + +## Use a different storage engine + +For information about the different storage engines, see +[Storage drivers](../../storage/storagedriver/index.md). +The default storage engine and the list of supported storage engines depend on +your host's Linux distribution and available kernel drivers. + +## Configure default logging driver + +Docker provides the [capability](../../config/containers/logging/index.md) to collect and view log data from all containers running on a host via a series of logging drivers. The default logging driver, `json-file`, writes log data to JSON-formatted files on the host filesystem. Over time, these log files expand in size, leading to potential exhaustion of disk resources. To alleviate such issues, either configure an alternative logging driver such as Splunk or Syslog, or [set up log rotation](/config/containers/logging/configure/#configure-the-default-logging-driver) for the default driver. If you configure an alternative logging driver, see [Use `docker logs` to read container logs for remote logging drivers](/config/containers/logging/dual-logging/). + +## Configure where the Docker daemon listens for connections + +By default, the Docker daemon listens for connections on a UNIX socket to accept requests from local clients. It is possible to allow Docker to accept requests from remote hosts by configuring it to listen on an IP address and port as well as the UNIX socket. For more detailed information on this configuration option take a look at "Bind Docker to another host/port or a unix socket" section of the [Docker CLI Reference](https://docs.docker.com/engine/reference/commandline/dockerd/) article. + +> Secure your connection +> +> Before configuring Docker to accept connections from remote hosts it is critically important that you +> understand the security implications of opening docker to the network. If steps are not taken to secure the connection, +> it is possible for remote non-root users to gain root access on the host. For more information on how to use TLS +> certificates to secure this connection, check this article on +> [how to protect the Docker daemon socket](https://docs.docker.com/engine/security/https/). +{: .warning} + +Configuring Docker to accept remote connections can be done with the `docker.service` systemd unit file for Linux distributions using systemd, such as recent versions of RedHat, CentOS, Ubuntu and SLES, or with the `daemon.json` file which is recommended for Linux distributions that do not use systemd. + +> systemd vs daemon.json +> +> Configuring Docker to listen for connections using both the `systemd` unit file and the `daemon.json` +> file causes a conflict that prevents Docker from starting. + +### Configuring remote access with `systemd` unit file + +1. Use the command `sudo systemctl edit docker.service` to open an override file for `docker.service` in a text editor. + +2. Add or modify the following lines, substituting your own values. + + ```none + [Service] + ExecStart= + ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375 + ``` + +3. Save the file. + +4. Reload the `systemctl` configuration. + + ```bash + $ sudo systemctl daemon-reload + ``` + +5. Restart Docker. + + ```bash + $ sudo systemctl restart docker.service + ``` + +6. Check to see whether the change was honored by reviewing the output of `netstat` to confirm `dockerd` is listening on the configured port. + + ```bash + $ sudo netstat -lntp | grep dockerd + tcp 0 0 127.0.0.1:2375 0.0.0.0:* LISTEN 3758/dockerd + ``` + +### Configuring remote access with `daemon.json` + +1. Set the `hosts` array in the `/etc/docker/daemon.json` to connect to the UNIX socket and an IP address, as follows: + + ```json + { + "hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"] + } + ``` + +2. Restart Docker. + +3. Check to see whether the change was honored by reviewing the output of `netstat` to confirm `dockerd` is listening on the configured port. + + ```bash + $ sudo netstat -lntp | grep dockerd + tcp 0 0 127.0.0.1:2375 0.0.0.0:* LISTEN 3758/dockerd + ``` + +## Enable IPv6 on the Docker daemon + +To enable IPv6 on the Docker daemon, see +[Enable IPv6 support](../../config/daemon/ipv6.md). + +## Troubleshooting + +### Kernel compatibility + +Docker cannot run correctly if your kernel is older than version 3.10 or if it +is missing some modules. To check kernel compatibility, you can download and +run the [`check-config.sh`](https://raw.githubusercontent.com/docker/docker/master/contrib/check-config.sh) +script. + +```bash +$ curl https://raw.githubusercontent.com/docker/docker/master/contrib/check-config.sh > check-config.sh + +$ bash ./check-config.sh +``` + +The script only works on Linux, not macOS. + +### `Cannot connect to the Docker daemon` + +If you see an error such as the following, your Docker client may be configured +to connect to a Docker daemon on a different host, and that host may not be +reachable. + +```none +Cannot connect to the Docker daemon. Is 'docker daemon' running on this host? +``` + +To see which host your client is configured to connect to, check the value of +the `DOCKER_HOST` variable in your environment. + +```bash +$ env | grep DOCKER_HOST +``` + +If this command returns a value, the Docker client is set to connect to a +Docker daemon running on that host. If it is unset, the Docker client is set to +connect to the Docker daemon running on the local host. If it is set in error, +use the following command to unset it: + +```bash +$ unset DOCKER_HOST +``` + +You may need to edit your environment in files such as `~/.bashrc` or +`~/.profile` to prevent the `DOCKER_HOST` variable from being set +erroneously. + +If `DOCKER_HOST` is set as intended, verify that the Docker daemon is running +on the remote host and that a firewall or network outage is not preventing you +from connecting. + +### IP forwarding problems + +If you manually configure your network using `systemd-network` with `systemd` +version 219 or higher, Docker containers may not be able to access your network. +Beginning with `systemd` version 220, the forwarding setting for a given network +(`net.ipv4.conf..forwarding`) defaults to *off*. This setting +prevents IP forwarding. It also conflicts with Docker's behavior of enabling +the `net.ipv4.conf.all.forwarding` setting within containers. + +To work around this on RHEL, CentOS, or Fedora, edit the `.network` +file in `/usr/lib/systemd/network/` on your Docker host +(ex: `/usr/lib/systemd/network/80-container-host0.network`) and add the +following block within the `[Network]` section. + +``` +[Network] +... +IPForward=kernel +# OR +IPForward=true +... +``` + +This configuration allows IP forwarding from the container as expected. + + +### `DNS resolver found in resolv.conf and containers can't use it` + +Linux systems which use a GUI often have a network manager running, which uses a +`dnsmasq` instance running on a loopback address such as `127.0.0.1` or +`127.0.1.1` to cache DNS requests, and adds this entry to +`/etc/resolv.conf`. The `dnsmasq` service speeds up +DNS look-ups and also provides DHCP services. This configuration does not work +within a Docker container which has its own network namespace, because +the Docker container resolves loopback addresses such as `127.0.0.1` to +**itself**, and it is very unlikely to be running a DNS server on its own +loopback address. + +If Docker detects that no DNS server referenced in `/etc/resolv.conf` is a fully +functional DNS server, the following warning occurs and Docker uses the public +DNS servers provided by Google at `8.8.8.8` and `8.8.4.4` for DNS resolution. + +```none +WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers +can't use it. Using default external servers : [8.8.8.8 8.8.4.4] +``` + +If you see this warning, first check to see if you use `dnsmasq`: + +```bash +$ ps aux |grep dnsmasq +``` + +If your container needs to resolve hosts which are internal to your network, the +public nameservers are not adequate. You have two choices: + +- You can specify a DNS server for Docker to use, **or** +- You can disable `dnsmasq` in NetworkManager. If you do this, NetworkManager + adds your true DNS nameserver to `/etc/resolv.conf`, but you lose the + possible benefits of `dnsmasq`. + +**You only need to use one of these methods.** + +### Specify DNS servers for Docker + +The default location of the configuration file is `/etc/docker/daemon.json`. You +can change the location of the configuration file using the `--config-file` +daemon flag. The documentation below assumes the configuration file is located +at `/etc/docker/daemon.json`. + +1. Create or edit the Docker daemon configuration file, which defaults to + `/etc/docker/daemon.json` file, which controls the Docker daemon + configuration. + + ```bash + $ sudo nano /etc/docker/daemon.json + ``` + +2. Add a `dns` key with one or more IP addresses as values. If the file has + existing contents, you only need to add or edit the `dns` line. + + ```json + { + "dns": ["8.8.8.8", "8.8.4.4"] + } + ``` + + If your internal DNS server cannot resolve public IP addresses, include at + least one DNS server which can, so that you can connect to Docker Hub and so + that your containers can resolve internet domain names. + + Save and close the file. + +3. Restart the Docker daemon. + + ```bash + $ sudo service docker restart + ``` + +4. Verify that Docker can resolve external IP addresses by trying to pull an + image: + + ```bash + $ docker pull hello-world + ``` + +5. If necessary, verify that Docker containers can resolve an internal hostname + by pinging it. + + ```bash + $ docker run --rm -it alpine ping -c4 + + PING google.com (192.168.1.2): 56 data bytes + 64 bytes from 192.168.1.2: seq=0 ttl=41 time=7.597 ms + 64 bytes from 192.168.1.2: seq=1 ttl=41 time=7.635 ms + 64 bytes from 192.168.1.2: seq=2 ttl=41 time=7.660 ms + 64 bytes from 192.168.1.2: seq=3 ttl=41 time=7.677 ms + ``` + +#### Disable `dnsmasq` + +##### Ubuntu + +If you prefer not to change the Docker daemon's configuration to use a specific +IP address, follow these instructions to disable `dnsmasq` in NetworkManager. + +1. Edit the `/etc/NetworkManager/NetworkManager.conf` file. + +2. Comment out the `dns=dnsmasq` line by adding a `#` character to the beginning + of the line. + + ```none + # dns=dnsmasq + ``` + + Save and close the file. + +4. Restart both NetworkManager and Docker. As an alternative, you can reboot + your system. + + ```bash + $ sudo restart network-manager + $ sudo restart docker + ``` + +##### RHEL, CentOS, or Fedora + +To disable `dnsmasq` on RHEL, CentOS, or Fedora: + +1. Disable the `dnsmasq` service: + + ```bash + $ sudo service dnsmasq stop + + $ sudo systemctl disable dnsmasq + ``` + +2. Configure the DNS servers manually using the + [Red Hat documentation](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html){: target="_blank" rel="noopener" class="_"}. + +### Allow access to the remote API through a firewall + +If you run a firewall on the same host as you run Docker and you want to access +the Docker Remote API from another host and remote access is enabled, you need +to configure your firewall to allow incoming connections on the Docker port, +which defaults to `2376` if TLS encrypted transport is enabled or `2375` +otherwise. + +Two common firewall daemons are +[UFW (Uncomplicated Firewall)](https://help.ubuntu.com/community/UFW) (often +used for Ubuntu systems) and [firewalld](https://firewalld.org) (often used +for RPM-based systems). Consult the documentation for your OS and firewall, but +the following information might help you get started. These options are fairly +permissive and you may want to use a different configuration that locks your +system down more. + +- **UFW**: Set `DEFAULT_FORWARD_POLICY="ACCEPT"` in your configuration. + +- **firewalld**: Add rules similar to the following to your policy (one for + incoming requests and one for outgoing requests). Be sure the interface names + and chain names are correct. + + ```xml + + [ -i zt0 -j ACCEPT ] + [ -o zt0 -j ACCEPT ] + + ``` + +### `Your kernel does not support cgroup swap limit capabilities` + +On Ubuntu or Debian hosts, You may see messages similar to the following when +working with an image. + +```none +WARNING: Your kernel does not support swap limit capabilities. Limitation discarded. +``` + +This warning does not occur on RPM-based systems, which enable these +capabilities by default. + +If you don't need these capabilities, you can ignore the warning. You can enable +these capabilities on Ubuntu or Debian by following these instructions. Memory +and swap accounting incur an overhead of about 1% of the total available memory +and a 10% overall performance degradation, even if Docker is not running. + +1. Log into the Ubuntu or Debian host as a user with `sudo` privileges. + +2. Edit the `/etc/default/grub` file. Add or edit the `GRUB_CMDLINE_LINUX` line + to add the following two key-value pairs: + + ```none + GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" + ``` + + Save and close the file. + +3. Update GRUB. + + ```bash + $ sudo update-grub + ``` + + If your GRUB configuration file has incorrect syntax, an error occurs. + In this case, repeat steps 2 and 3. + + The changes take effect when the system is rebooted. + +## Next steps + +- Take a look at the [Get started](../../get-started/index.md) training modules to learn how to build an image and run it as a containerized application. +- Review the topics in [Develop with Docker](../../develop/index.md) to learn how to build new applications using Docker.