Ubuntu18.04 安装docker教程

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

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# 使用mirrors.ustc.edu.cn站点的镜像,在此之前需要了解一下这个站点是否可靠
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
    "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

# 查看版本 apt-cache madison docker-ce
# 选择版本,格式如下: sudo apt-get install docker-ce= docker-ce-cli= containerd.io
# 这里的最新版本是5:19.03.8~3-0~ubuntu-bionic,所以我替换成5:19.03.8~3-0~ubuntu-bionic
sudo apt-get install docker-ce=5:19.03.8~3-0~ubuntu-bionic docker-ce-cli=5:19.03.8~3-0~ubuntu-bionic containerd.io

# 设置开机自启动
sudo systemctl enable docker
sudo systemctl start docker

# 申请阿里云加速,https://cr.console.aliyun.com/cn-hangzhou/mirrors
# 注意要替换下面的https://xxxxxx.mirror.aliyuncs.com成为自己的专属加速地址
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

# 测试是否成功
sudo docker run hello-world 
# 等待一会儿(1分钟内)抓取之后,显示出下文即可
#Hello from Docker!
#This message shows that your installation appears to be working correctly.
#
#To generate this message, Docker took the following steps:
# 1. The Docker client contacted the Docker daemon.
# 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
#    (amd64)
# 3. The Docker daemon created a new container from that image which runs the
#    executable that produces the output you are currently reading.
# 4. The Docker daemon streamed that output to the Docker client, which sent it
#    to your terminal.
#
#To try something more ambitious, you can run an Ubuntu container with:
# $ docker run -it ubuntu bash
#
#Share images, automate workflows, and more with a free Docker ID:
# https://hub.docker.com/
#
#For more examples and ideas, visit:
# https://docs.docker.com/get-started/

你可能感兴趣的:(Linux)