2 Operation and maintenance-ubuntu16.04.6xenial-basic environment construction-install docker-ce

1 Installation requirements

1. It must be a computer with a 64-bit CPU architecture. Docker currently does not support 32-bit CPUs;
2. Runs Linux3.8 or higher kernel, and the CentOS kernel version cannot be lower than 3.10;
3. The kernel must support a suitable storage Driver, support overlay2, aufs and btrfs, docker-ce uses overlay by default;
4. The kernel must support and enable cgroup and namespace functions.


2 Installation method

2.1 Install with script

#采用脚本安装,curl https://get.docker.com/ | sudo sh
#访问url输出到sh文件,执行阿里云镜像获取
curl -fsSL get.docker.com -o get-docker.sh && \
sh get-docker.sh --mirror Aliyun

2.2 Use warehouse installation

2.2.1 Official website warehouse

1 Set up the repository

#更新apt包索引,安装包以允许apt通过HTTPS使用存储库
sudo apt-get update && \
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
#添加Docker的官方GPG密钥,设置存储库(官方数据源)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

2 Install the latest version

#更新apt包索引,安装docker
apt-get update && \
apt-get install -y docker-ce docker-ce-cli containerd.io

3 Install the specified version

#更新apt包索引,安装docker
apt-get update 
#列出版本
apt-cache madison docker-ce
#安装指定版本,sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
sudo apt-get install docker-ce=5:18.09.1~3-0~ubuntu-xenial docker-ce-cli=5:18.09.1~3-0~ubuntu-xenial containerd.io

2.2.2 Tsinghua Warehouse

#设置清华数据源
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list
#删除安装过的docker,更新源
sudo apt-get remove docker docker-engine docker.io && \
sudo apt-get update
#安装依赖,添加秘钥,更新源,进行安装
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
sudo apt-get update && \
sudo apt-get install docker-ce

2.3 Install with installation package

Here, wget is used to obtain the installation package from the Internet for installation. You can also download the installation package yourself and install it locally.

1 Use wget to obtain the installation package from the Internet

wget --no-check-certificate \
https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/containerd.io_1.2.6-3_amd64.deb \
https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce-cli_19.03.1~3-0~ubuntu-xenial_amd64.deb \
https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_19.03.1~3-0~ubuntu-xenial_amd64.deb

2 Installation

sudo dpkg -i *.deb && apt-get -f install

Which is apt-get -f installequivalent to apt-get --fix-broken installthe dependency of the repair package

3 configuration

3.1 Configure Mirror Accelerator

1 Modify files

vi /etc/docker/daemon.json

2 Add the following content to the file

{
        "registry-mirrors":[
                "https://registry.docker.cn.com"
        ]
}

3 Restart docker to make it effective

systemctl restart docker

4 verification

docker info

3.2 Configuration component docker-compose

This component can be used to start multiple containers at once, eliminating the trouble of manually using shell scripts to start containers multiple times.
1 Enter the installation directory

cd /usr/local/bin/

2 Download components

curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

3 Increase execution authority

chmod +x docker-compose

4 Verify the component version

docker-compose version

4 Uninstall

1 Uninstall the old version

sudo apt-get remove docker docker-engine docker.io containerd runc

2 Uninstall the package

sudo apt-get purge docker-ce

3 Clear the cache The
directory /var/lib/docker/ keeps the contents including images, containers, volumes and networks, and clear them as needed

sudo rm -rf /var/lib/docker

5 Upgrade

apt-get update

or

apt-get install docker-engine

Guess you like

Origin blog.csdn.net/weixin_45544465/article/details/100012878