Installation tutorial for Docker and Docker Compose under Linux operating system (including offline one-click installation resource package for x86 and arm64 platforms)

Introduction

This article will provide a detailed introduction to the installation tutorial of Docker and Docker Compose under Linux.
Directory 3 is the Docker offline installation resource package for x86 and arm64 platforms, including Docker Compose and one-click installation script usage tutorials.

Related article references:

Commonly used basic commands for Docker
Docker batch cleanup and deletion of images and containers Commonly used commands

The version is as follows

name Version
CentOS 7.6+

1. Docker installation (online installation)

For other operating systems such as openEuler, you can use yum search docker-ce or apt search docker-ce and other commands to query, and then install it directly. Or
refer to directory 3 for offline installation .
The following steps take centos as an example .

1.1 Install yum tool

First, you need to connect the host or virtual machine to the Internet and install the yum tool.

yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2 --skip-broken

1.2 Update local mirror source

 # 设置docker镜像源 
 yum-config-manager \
    --add-repo \
     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
     sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

 yum makecache fast

1.3 Install docker

#查看版本列表 yum list docker-ce --showduplicates | sort -r
[root@k8s-node01 ~]# yum list docker-ce --showduplicates | sort -r
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
已加载插件:fastestmirror, langpacks
已安装的软件包
可安装的软件包
Loading mirror speeds from cached hostfile
 * epel: mirrors.bfsu.edu.cn
 * elrepo: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.23-3.el7                   docker-ce-stable
#选择版本安装 不加版本号 默认最新版本
# yum install -y docker-ce
yum -y install docker-ce-20.10.6-3.el7

# 查看版本 docker -v
[root@k8s-node01 ~]# docker -v
Docker version 20.10.22, build 3a2c30b

1.4 Configure image acceleration (optional)

mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://14pfyl2z.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

1.5 Set up auto-start at boot

systemctl enable docker  # 设置开机自启

1.6 Uninstall (optional)

# 如果之前安装过旧版本的Docker,可以使用下面命令卸载
# 停止容器服务
docker ps -a | awk '{print $1}' | xargs docker stop
# 删除容器
docker ps -a | awk '{print $1}' | xargs docker rm
# 删除镜像
docker images | awk '{print $3}' | xargs docker rmi
# 停止docker服务
systemctl stop docker 
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce

2. Installation of Docker Compose

2.1 Download binary files

Visit https://github.com/docker/compose/releases/ , select the version, download it with the browser, and then upload it to the server /usr/local/bin/ directory. Or use the following command directly on the server.

# Linux下需要通过命令下载
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

2.2 Modify permissions

# 修改权限
chmod +x /usr/local/bin/docker-compose
# 查看版本 docker-compose -v
[root@k8s-node01 ~]# docker-compose -v
docker-compose version 1.23.1, build b02f1306

3. Docker offline installation resource package for x86 and arm64 platforms

3.1 Download resource package

The current offline package resource package version is 18.09.9. If you need other versions, please visit https://download.docker.com/linux/static/stable/
to download the required version and place it with the resource package script file install-docker .sh
The execution installation command in the 3.2 tutorial on the same level directory is modified to ./install-docker.sh. Just download the offline docker compressed package and you can
use Docker Compose. You can directly refer to 2.1 to download the binary file replacement update.

1.openEuler (arm64 platform) click to download
2.centos (x86 platform) click to download

3.2 Installation and usage tutorial

The compression format of the resource package is zip. After decompressing it on the Windows platform, upload it to the target server and run the following command.

#安装docker
chmod 755 install-docker.sh
./install-docker.sh docker-18.09.9.tgz
#安装docker-compose
cp docker-compose /usr/local/bin/
chmod 777 /usr/local/bin/docker-compose
docker-compose -v

3.3 Uninstall

#停止容器服务
docker ps -a | awk '{print $1}' | xargs docker stop
#删除容器
docker ps -a | awk '{print $1}' | xargs docker rm
#删除镜像
docker images | awk '{print $3}' | xargs docker rmi
#停止docker服务 
systemctl stop docker
#删除docker二进制文件
rm -f /usr/bin/containerd
rm -f /usr/bin/containerd-shim
rm -f /usr/bin/ctr
rm -f /usr/bin/docker
rm -f /usr/bin/dockerd
rm -f /usr/bin/docker-init
rm -f /usr/bin/docker-proxy
rm -f /usr/bin/runc
#卸载docker-compose二进制文件
rm -f /usr/local/bin/docker-compose

References to previous articles:
Commonly used basic commands for Docker
Commonly used commands for Docker batch cleanup and deletion of images and containers

Guess you like

Origin blog.csdn.net/ChennyWJS/article/details/131781839