This article introduces the installation process of Docker in Linux system. Since I have always used ubuntu system, I use this as the platform, specifically Ubuntu 16.04, 64-bit system. Docker has developed rapidly in recent years. Since 2017, Docker has basically released a version every month. The previous version number was a number, but now it has been changed to the form of year + month, namely yy.mm. For example, I first installed Docker version 17.09, which was released in September 2017. Docker has two versions: Docker-CE (Community Edition, Docker Community Edition) and Docker-EE (Enterprise Edition, Docker Enterprise Edition). We generally use Docker-CE to meet most application situations.

The simplest solution

The Ubuntu repository already has a docker source, so you can install it directly using the apt-get command. 1. Update source

sudo apt-get update
Copy the code

2, installation,

sudo apt-get install docker.io
Copy the code

Note that this is an earlier version of the installation. When I installed this command, version 1.13 was installed.

The official recommended installation mode

1. Update source

sudo apt-get update
Copy the code

2, set APT to use source via HTTPS

sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
Copy the code

Add official Docker GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Copy the code

4. Check whether the added key is correct. Check whether there is a 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 fingerprint.

$ sudo apt-key fingerprint 0EBFCD88
Copy the code

Local output:

pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE  deb) <[email protected]> sub 4096R/F273FCD8 2017-02-22Copy the code

Add stable repository

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
Copy the code

6. Update sources

sudo apt-get update 
Copy the code

At this time, you can check which versions are available:

Sudu apt - cache Madison docker - ce docker - ce | from. 03.5 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | from. 03.4 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | from. 03.3 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | from. 03.2 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | from. 03.1 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | from. 03.0 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | easier. 09.9 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | easier. 09.8 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu Xenial/stable amd64 Packages docker - ce | 18.03.1 ~ ce - 0 ~ ubuntu | https://download.docker.com/linux/ubuntu xenial/stable Amd64 Packages docker - ce | 18.03.0 ~ ce - 0 ~ ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages Docker - ce | 17.03.1 ~ ce - 0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 PackagesCopy the code

Install Docker:

sudo apt-get install docker-ce
Copy the code

Specified versions can be installed:

Sudo apt - get the install docker - ce = a graceful. 03.5 ~ 3-0 ~ ubuntu - xenialCopy the code

Check the Docker version

# Docker-Vdocker version 17.09.0-CE, build afdb6d4Copy the code

If the version number information is displayed, the installation is successful.

Domestic image installation

Many resources of Docker are in foreign servers, so the access may be slow (or even inaccessible). Many domestic docker service vendors have image resources. Therefore, if the installation is not successful according to the official instructions, the domestic image installation can be used, and the version is basically the latest. 1. Update source

# apt-get update
Copy the code

Install curl:

# apt-get install curl -y
Copy the code

2, installation,

# curl -sSL https://get.daocloud.io/docker | sh
Copy the code

The following information is displayed:

# Executing docker install script, commit: 490beaa+ sh -c apt-get update -qq >/dev/null+ sh -c apt-get install -y -qq apt-transport-https ca-certificates curl software-properties-common >/dev/null+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg"; | apt-key add -qq - >/dev/null+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial edge" > /etc/apt/sources.list.d/docker.list+ [ ubuntu = debian ]+ sh -c apt-get update -qq >/dev/null+ sh -c apt-get install -y -qq docker-ce >/dev/null+ sh -c docker versionClient:Version: 17.10.0-ceAPI Version: 1.33Go Version: go1.8.3Git commit: F4ffd25Built: Tue Oct 17 19:04:16 2017 OS/Arch: Linux/amd64Server: Version: 17.10.0 - ceAPI Version: 1.33 (minimum version 1.12)Go version: go1.8.3Git Commit: f4ffd25Built: Tue Oct 17 19:02:56 2017OS/Arch: linux/amd64Experimental: falseIf you would like to use Docker as a non-root user, you should now consideradding your user to the "docker" group with something like: sudo usermod -aG docker your-userRemember that you will have to log out and back in for this to take effect! WARNING: Adding a user to the "docker" group will grant the ability to run containers which can be used to obtain root privileges  on the docker host. Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface for more information.Copy the code

If the preceding information is displayed, Docker has been successfully installed.

Add user to docker group

If you use a common user to execute the docker command, an error occurs as follows:

$ docker psGot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/json: dial Unix/var/run/docker. The sock: connect: permission deniedCopy the code

This is caused by insufficient permissions of ordinary users. Take a look at the permission of the error message /var/run/docker.sock file.

$ ll /var/run/docker.socksrw-rw---- 1 root docker 0 Dec 23 15:12 /var/run/docker.sock=
Copy the code

This file has the root permission and belongs to the Docker group. Therefore, the solution is to add regular users to the Docker group with the following command:

sudo gpasswd -a ${USER} dockersudo newgrp - docker
Copy the code

This eliminates the need to frequently switch to root when using Docker later.

Change the image file storage path

Stop docker service:

# systemctl stop docker
Copy the code

Modify/lib/systemd/system/docker. The service documents, additional – graph after ExecStart command < directory > (note: the default without this option), the sample:

ExecStart=/usr/bin/dockerd -H fd:// --graph /mnt/docker
Copy the code

Reload the configuration file and start the Docker service:

# systemctl start docker # systemctl start dockerCopy the code

Note 1: You can run the docker info command to check whether the modification is successful. Note 2: The original image needs to be manually deleted.

The default directory is /var/lib/docker, so you can make a connection file, so you don’t need to modify the configuration file.

systemctl stop dockerln -s /home/latelee/workshop/docker/ /var/lib/dockersystemctl start docker
Copy the code

The configuration file

The Docker configuration file is /etc/docker/daemon.json. Default does not exist.

cat > /etc/docker/daemon.json <<-EOF{  "registry-mirrors": [    "https://a8qh6yqv.mirror.aliyuncs.com",    "http://hub-mirror.c.163.com"  ],  "exec-opts": ["native.cgroupdriver=systemd"]}EOF
Copy the code

Registry -mirrors specifies the address of the Docker image to speed up the download of the image. Exec-opts native-cgroupDriver =systemd: specifies the cGroup driver as systemd

Foreign: CentOS system installation

If there is an old version, delete it:

sudo yum remove docker  docker-common docker-selinux docker-engine
Copy the code

Otherwise, a conflict is displayed and the installation cannot be performed:

Error: the docker - ce - cli conflicts with 2: the docker - 1.13.1-203. Git0be3e21. El7. Centos. X86_64Error: Docker - ce conflicts with 2: the docker - 1.13.1-203. Git0be3e21. El7. Centos. X86_64Copy the code

System installation tools:

Sudo yum install -y yum-utils device-mapper-persistent-data LVM2 Yum-util provides yum-config-Manager functionality, device-mapper-persistent-data, and LVM2 are devicemapper driver dependenciesCopy the code

Add domestic source (Aliyun) :

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code

Generate cache:

sudo yum makecache 
Copy the code

Installation:

Sudo yum install docker-ce sudo yum install docker-ceCopy the code

View version:

# Docker-vdocker version 19.03.13, build 4484C46d9dCopy the code

It is not started by default, prompting:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Copy the code

Manually start docker services:

# systemctl start docker
Copy the code

Automatic startup upon startup:

# systemctl enable docker
Copy the code

Other configurations, such as accelerators and storage directories, are not substantially different from those described above.

If IP forwarding is not enabled, run the following command:

# echo "net.ipv4.ip_forward=1" >> /usr/lib/sysctl.d/00-system.conf
Copy the code

Restarting the Network Service

# systemctl restart network
Copy the code

Check whether the modification is successful

#  sysctl net.ipv4.ip_forward
Copy the code

You can also restart the machine.

Start the research

Docker can not be started directly with the dockerd command, you must use systemd, otherwise prompt:

# /usr/bin/dockerd -H fd://no sockets found via socket activation: make sure the service was started by systemd
Copy the code

Based on this experiment, it can be seen that to run Docker on embedded ARM, we need to use SystemD instead of default init program.

Practice to record

Deleting a file from the container and then saving it as an image does not affect the original image. If the original image size is 4GB, start it, delete a large number of files from the container, and save them as images. The new image size is still 4GB. For example, if the original image is 100MB, start the image and install a large amount of software in the container. For example, if the original image is 1GB, save the image and add 1GB to the new image. If the temporary file is deleted, assume that it is 500MB, the new image is added by 500MB. Conclusion: Add new files on the basis of small image, software, delete cache temporary files.