When Docker encounters Systemd

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Recent experiments on upgrading kubernetes clusters, from the original k8s 1.3.7 to the latest version of K8s 1.5.1. K8s has introduced Kubeadm since version 1.4, attempting to streamline the installation and use of k8s and enhance the developer experience. However, Kubeadm only supports Ubuntu version 16.04 and above, so we will encounter another problem before upgrading the k8s cluster: Ubuntu 16.04 has been replaced by the upstart initialization system for the SYSTEMD initialization system, Ubuntu The use and configuration of the Docker engine on 16.04 differs from what it used to be on Ubuntu 14.04. Docker is one of the container engines supported by k8s and one of the most mainstream container engines, and it is also a prerequisite for the subsequent use of Docker configuration and use k8s. So here is the plan to document how Docker and Systemd coexist ^0^.

One, Ubuntu 16.04 install Docker

Aliyun currently does not provide the official Ubuntu 16.04 ECS, the maximum support is only to Ubuntu 14.04.4. Therefore, the use of 16.04 on Aliyun ECS requires manual upgrade to 16.04 (but it is recommended to do a snapshot before upgrade, once the upgrade fails, good recovery). The updated Ubuntu environment information is as follows:

Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-58-generic x86_64)

The KUBEADM document says that the Docker 1.11.2 version is more of a match, but it doesn't seem to be a big problem for newer versions. Here we install the latest stable release:docker 1.12 that can be found now. 5:

# docker versionClient: Version:      1.12.5 API version:  1.24 Go version:   go1.6.4 Git commit:   7392c3b Built:        Fri Dec 16 02:42:17 2016 OS/Arch:      linux/amd64Server: Version:      1.12.5 API version:  1.24 Go version:   go1.6.4 Git commit:   7392c3b Built:        Fri Dec 16 02:42:17 2016 OS/Arch:      linux/amd64

The above is the version information that you can output when you install Docker successfully, OH ^0^.

The method of installing Docker is changing with the rapid evolution of Docker, and its methods tend to stabilize as docker matures. The official offer to install Docker in Ubuntu has become mainstream, and we are no exception here to refer to this approach. But this approach has the premise that you'd better be equipped with the "Qiang" (QI), otherwise slow, or even unsuccessful.

The detailed steps are as follows: (the familiar audience can skip the ^_^)

1. Get Key from Keyserver

# apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys  58118E89F3A912897C070ADBF76221572C52609DExecuting: /tmp/tmp.OoFaQ0V0gx/gpg.1.sh --keyserverhkp://p80.pool.sks-keyservers.net:80--recv-keys58118E89F3A912897C070ADBF76221572C52609Dgpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.netgpg: key 2C52609D: public key "Docker Release Tool (releasedocker) 
  
   
    
   " importedgpg: Total number processed: 1gpg:               imported: 1  (RSA: 1)
  
   

2. Add a Docker source

Create a/etc/apt/sources.list.d/docker.list file, write:

deb https://apt.dockerproject.org/repo ubuntu-xenial main

To perform the Apt-get update package information:

... ...Get:11 https://apt.dockerproject.org/repo ubuntu-xenial InRelease [30.2 kB]Fetched 30.2 kB in 2s (14.1 kB/s)Reading package lists... Done

3. Installing Docker engine

Install the Docker engine by executing the installation command:

# apt install docker-engine... ...Setting up docker-engine (1.12.5-0~ubuntu-xenial) ...Setting up liberror-perl (0.17-1.2) ...Setting up git-man (1:2.7.4-0ubuntu1) ...Setting up git (1:2.7.4-0ubuntu1) ...Processing triggers for libc-bin (2.23-0ubuntu5) ...Processing triggers for systemd (229-4ubuntu13) ...Processing triggers for ureadahead (0.100.0-19) ...

To verify the installation results:

# which docker/usr/bin/docker# docker version... ... //输出和上一节相同的结果# ps -ef|grep dockerroot     22132     1  0 11:18 ?        00:00:00 /usr/bin/dockerd -H fd://root     22162 22132  0 11:18 ?        00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc

After installation, the Docker engine starts automatically.

Second, the Docker service enable and start to stop

The script that controls the boot and start-up operation of the Docker service has changed from the/etc/init.d/docker of the upstart initialization system to the/lib/systemd/system/docker.service of the SYSTEMD initialization system.

Under SYSTEMD, the script path for the Docker service can be found using the following command:

# systemctl show --property=FragmentPath dockerFragmentPath=/lib/systemd/system/docker.service

Use the following command to see if the Docker service is powered on:

# systemctl is-enabled dockerenabled

The Systemctl enable and disable commands enable you to power on or off from boot.

Traditional Ubuntu starts, stops, or restarts services via service Docker Start/stop/restart, and after switching to SYSTEMD, we need to use Systemctl Start/stop/restart Docker to start, Stop or restart the service.

Third, Docker's Environmentfile

Previously we set up a http_proxy for Docker engine, set –insecure-registry or –registry-mirror, configure a DNS what, can be through the/etc/default/ The docker_opts in Docker and the environment variables associated with export are implemented. But under Ubuntu 16.04 This configuration file becomes this:

# Docker Upstart and SysVinit configuration file## THIS FILE DOES NOT APPLY TO SYSTEMD##   Please see the documentation for "systemd drop-ins":#   https://docs.docker.com/engine/articles/systemd/... ...

Here's the problem! How do we configure Docker engine? Docker officially recommends creating a configuration file (such as http-proxy.conf) below the path below to override the configuration in the default Docker.service file:

/etc/systemd/system/docker.service.d

But after the test (after Systemctl daemon-reload; Systemctl restart Docker), the discovery does not take effect.

Let's use Environmentfile to configure the Docker engine. Edit the/lib/systemd/system/docker.service file and add the following:

ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTSEnvironmentFile=-/etc/default/docker

Accustomed to configuring docker_opts with/etc/default/docker configuration, the file was used directly in Environmentfile.

///etc/default/dockerDOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"# If you need Docker to use an HTTP proxy, it can also be specified here.#export http_proxy="http://127.0.0.1:3128/"http_proxy="http://xxxxx"https_proxy="xxxx"no_proxy="127.0.0.1,localhost"

After saving, execute:

systemctl daemon-reloadsystemctl restart docker

You will find that the configuration is in effect.

People who are often exposed to/etc/default/docker will find that the Export keyword in front of the http_proxy variables in the above file is gone. Yes, in the SYSTEMD environment, export is no longer necessary, and if you add export, it will cause the configuration does not take effect.

Iv. log of the Docker engine

Finally, where is the log for the Docker engine? Wasn't it under/var/log/upstart/before? In Ubuntu 16.04, this directory is not even seen in the image of Docker.

Under SYSTEMD, we need to move out the Journalctl tool. To see a real-time log of Docker service, do this:

# journalctl -u docker -f

See history log:

# journalctl --since "1 hour ago" -u docker

For more journalctl usage, refer to its man pages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.