01.安装与启动Docker
安装¶
对于 Linux 发行版,一般可以直接去各大开源镜像站,上面有专门的安装方式,一般都是差不多
- 阿里镜像:https://developer.aliyun.com/mirror/docker-ce
- 腾讯镜像:https://mirrors.cloud.tencent.com/help/docker-ce.html
- 华为云开源镜像: https://mirrors.huaweicloud.com/mirrorDetail/5ea14d84b58d16ef329c5c13?mirrorName=docker-ce&catalog=docker
腾讯云镜像安装 docker(Centos)¶
# 替换docker-ce 源
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.cloud.tencent.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# 安装
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
腾讯云镜像安装 Docker(Ubuntu)¶
# 卸载旧版本
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Add Docker's official GPG key:
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update
# 这里需要修改一下,镜像中默认只安装docker-ce
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 启动
sudo docker run hello-world
启动 docker¶
默认安装之后,是不会开机启动的,需要自己设置成开机启动,不如每次重启电脑,都需要自己启动Docker
# 启动
systemctl start docker
# 停止
systemctl stop docker
# 重启
systemctl restart docker
# 开机启动
systemctl enable docker
# 关闭开机启动
systemctl disable docker
# 列出所有启动项:
systemctl list-unit-files
# 使用grep过滤一下开启的grep enabled
sudo systemctl list-unit-files | grep enabled