Docker安装教程记录

更换源

sudo apt-get update
sudo apt-get install vim
vim /etc/apt/sources.list

百度对应的发行版国内源

deb https://mirrors.tuna.tsinghua.edu.cn/debian stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
#backports请按需使用
#deb https://mirrors.tuna.tsinghua.edu.cn/debian stretch-backports main contrib non-free 
#buster请按需使用
#deb https://mirrors.tuna.tsinghua.edu.cn/debian buster main

刷新

sudo apt-get update

Docker

卸载docker

sudo apt-get remove docker

安装依赖包(apt可以使用https仓库)

apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

添加docker官方GPG key

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

添加仓库

sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian wheezy stable"
//官方源 
//add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable"

备注:

  • arch=amd64需要根据本机CPU品牌和位数进行选择

  • X86:32位(一般i386是32位CPU的统称)

  • X64:64位(代表CPU:IA64,现在几乎没有这样纯粹的64位CPU,都是兼容32位的64位CPU)

  • X86_64:兼容32位的64位CPU,是64位(Intel的叫法)

  • AMD64:兼容32位的64位CPU,是64位(AMD的叫法)

安装docker

sudo apt-get update
sudo apt-get install docker-ce

if报错:aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Debian/buster

就把 下面仓库地址添加到源文件 /etc/apt/sources.list 在运行安装命令

deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian wheezy stable

sudo service docker start ,然后执行 sudo docker version

sudo docker run hello-world

Docker命令:

启动docker:

systemctl start docker

停止docker:

systemctl stop docker

重启docker:

systemctl restart docker

查看docker状态:

systemctl status docker

开机启动:

systemctl enable docker

查看docker概要信息

docker info

查看docker帮助文档

docker --help

查看镜像

docker images

REPOSITORY:镜像名称
TAG:镜像标签
IMAGE ID:镜像ID
CREATED:镜像的创建日期(不是获取该镜像的日期)
SIZE:镜像大小
这些镜像都是存储在Docker宿主机的/var/lib/docker目录下

从公用仓库中搜索

docker search 镜像名称

NAME:名称 = 仓库名称+"/"+镜像名称
DESCRIPTION:镜像描述
STARS:用户评价,反应一个镜像的受欢迎程度
OFFICIAL:是否官方
AUTOMATED:自动构建,表示该镜像由Docker Hub自动构建流程创建的

拉去镜像,默认最新的镜像

docker pull 镜像名称

删除镜像

docker rmi 镜像ID/镜像名称
##删除所有镜像
docker rmi `docker images -q`

todo

Q.E.D.