参考:https://docs.docker.com/engine/install/ubuntu/

Docker安装

设置存储库

更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:

sudo apt-get update && sudo apt upgrade 
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

添加Docker的官方GPG密钥:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

使用以下命令来设置稳定的存储库。

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装DOCKER引擎

更新apt程序包索引,并安装最新版本的Docker Engine和容器化的容器,或转到下一步以安装特定版本:

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

配置

添加用户到Docker组

sudo usermod -aG docker yjw #yjw是我的用户名
cat /etc/group | grep docker #查看

查看Docker版本

docker --version
docker system info

添加国内源

sudo vim /etc/docker/daemon.json

添加如下

{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] 
}
{
 "registry-mirrors" : [
   "http://docker.mirrors.ustc.edu.cn",
   "http://registry.docker-cn.com",
   "https://mirror.ccs.tencentyun.com",
   "http://hub-mirror.c.163.com"
 ],
 "insecure-registries" : [
   "registry.docker-cn.com",
   "docker.mirrors.ustc.edu.cn"
 ],
 "debug" : true,
 "experimental" : true
}

Docker中国区官方镜像
https://registry.docker-cn.com

网易
http://hub-mirror.c.163.com

ustc
https://docker.mirrors.ustc.edu.cn

中国科技大学
https://docker.mirrors.ustc.edu.cn

重启服务

systemctl restart docker
sudo systemctl status docker

测试

sudo docker run hello-world
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/

查看镜像

docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    d1165f221234   6 weeks ago   13.3kB

Docker 命令

启动命令:

sudo systemctl start docker

查看状态:

sudo systemctl status docker

重启docker:

sudo systemctl restart docker

关闭命令:

sudo systemctl stop docker

Docker 卸载

卸载docker:

sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get autoremove docker docker-ce docker-engine  docker.io  containerd runc

删除docker其他没有没有卸载

dpkg -l | grep docker
sudo apt-get autoremove docker-ce-*

删除docker的相关配置&目录

sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

删除所有带 rc 标记的dpkg包

dpkg -l | grep ^rc | cut -d' ' -f3 | sudo xargs dpkg --purge
最后修改:2021 年 04 月 21 日
男宾一位~ 欢迎下次再来!