Linux download and install docker and configure image acceleration

Linux download and install docker and configure image acceleration

Table of contents

Linux download and install docker and configure image acceleration

1. Install docker

2. Start docker

3. Configure mirror acceleration


1. Install docker

yum update

If the linux system has already installed docker, execute the following command

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

First of all, you need to connect the virtual machine to the Internet and install the yum tool

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

--skip-brokenIgnore packages with dependency issues

Then update the local mirror source:

# 设置docker镜像源:阿里云的镜像
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
# 添加docker-ce的下载地址    
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
​
# 创建元数据缓存
yum makecache fast

sed can process and edit text files according to the instructions of the script.

  • i : insert, i can be followed by strings, and these strings will appear in a new line (the current previous line);

Then enter the command:

yum install -y docker-ce

docker-ce is a free version for the community. Wait for a while, docker will be installed successfully.

The provided virtual machine is already installed

2. Start docker

Docker applications need to use various ports, and modify the firewall settings one by one. It is very troublesome, so it is recommended that you close the firewall directly!

Before starting docker, be sure to close the firewall! !

Before starting docker, be sure to close the firewall! !

Before starting docker, be sure to close the firewall! !

# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld

Start docker by command:

systemctl start docker  # 启动docker服务
systemctl enable docker # 开机自启动docker服务
​
systemctl stop docker  # 停止docker服务
systemctl restart docker  # 重启docker服务

Then enter the command to view the docker version:

docker -v

As shown in the picture:

3. Configure mirror acceleration

The network speed of docker's official mirror warehouse is poor, so we need to set up a domestic mirror service:

 Refer to Alibaba Cloud's image acceleration document: Alibaba Cloud Login - Welcome to Alibaba Cloud, a secure and stable cloud computing service platform

# 创建目录
sudo mkdir -p /etc/docker
# 编辑文件,添加以下内容
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://6twji7l1.mirror.aliyuncs.com"]
}
EOF
# 重新加载文件
sudo systemctl daemon-reload
# 重启docker
sudo systemctl restart docker

Guess you like

Origin blog.csdn.net/weixin_56602545/article/details/130150580