Docker 安装(官方安装方法)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker 安装(官方安装方法)相关的知识,希望对你有一定的参考价值。

写在前面

由于Docker-Engine Docker官方已经不推荐使用,无法安装了,所以现在安装Docker-CE。

参考官方文档 https://docs.rancher.cn/rancher2x/install-prepare/basic-environment-configuration.html#_4-1-docker%E5%AE%89%E8%A3%85

安装步骤

1.关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

2.添加yum源

yum install ca-certificates ;
update-ca-trust;
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-bak #备份

cat << ‘EOF‘ > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

3.指定Docker版本

export docker_version=18.09.9;

4.删除旧的docker组件

apt-get remove docker docker-engine docker.io containerd runc -y;

5.更新 apt 源

apt-get update;

6.对系统进行全面的更新升级,推荐升级一下(可选)

apt-get -y upgrade;

7.安装必要的一些系统工具

apt-get -y install apt-transport-https ca-certificates
curl software-properties-common bash-completion gnupg-agent;

8.安装GPG证书

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg |
sudo apt-key add -;

9.添加Docker APT 源

add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable";

10.更新并安装 Docker-CE

apt-get -y update;
install_version=$( apt-cache madison docker-ce | grep ${docker_version} | awk ‘{print $3}‘ );

11.允许降级安装

apt-get -y install docker-ce=${install_version} docker-ce-cli=${install_version} --allow-downgrades;

12.把当前用户加入docker组

usermod -aG docker $NEW_USER;

13.设置开机启动

systemctl start docker;
systemctl enable docker;

14.清理不需要的依赖

apt-get autoremove -y

锁定Docker版本

安装yum-plugin-versionlock插件

yum install yum-plugin-versionlock

锁定软件包

yum versionlock add docker-ce docker-ce-cli
yum versionlock add docker-ce docker-ce-cli
yum versionlock list

解锁指定的软件包

yum versionlock delete <软件包名称>

解锁所有的软件包

yum versionlock clear

以上是关于Docker 安装(官方安装方法)的主要内容,如果未能解决你的问题,请参考以下文章

如何使用官方 PHP Docker 镜像方法安装 php-redis 扩展?

Docker的安装和使用说明——Docker for Windows

Docker的安装和使用说明——Docker for Windows

史上最全(全平台)docker安装方法!

docker自动化安装及基本使用

docker-Django容器化部署