Debian下安装docker方法详解

一、安装之前的准备

之前我在上一篇讲过Ubuntu下如何安装docker,但是Ubuntu在实际使用的过程中,不论是系统的流畅性还是稳定性方面感觉都不能达到我们的需求,后面在朋友的建议下,我吧Ubuntu换成了Debian,Debian到现在为止最新版本是10.0(Buster)。系统的镜像文件在网上也比较容易搜索到。

虚拟机我选择的是virtualBox,下载好了Debian的镜像之后(这里我选择的是Debian10.0 Buster版本),分配好内存和磁盘大小,这里建议设置的磁盘空间是20G+,在启动的时候选择我们下载好的镜像。有一点想要强调的是,在安装的过程中在设置磁盘分区的时候,建议大家选择第一个(All files in one partition).
![分区请选择第一个](https://img-blog.csdnimg.cn/20200312211910629.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L01yX0dvcmdyZQ==,size_16,color_FFFFFF,t_70)

另外,最好不要安装图形化界面,因为会占用比较大的空间,而且我们完全课程通过git客户端来远程操作虚拟机,所以Debian你在这里更多的像是扮演一个服务器的角色。

二、安装之前的系统设置

ok,在安装好了之后,在开启Buster之后,建议大家第一步先进系统,查看是否打开了远程可登陆系统。

vi /etc/ssh/sshd_config

在打开的文件里面,把PermitRootLogin yes的注释打开。
PasswordAuthencation yes的注释也取消掉(这里的属性值之前可能是no,要手动修改成yes),然后启动ssh服务。

/etc/init.d/ssh start

然后在windows里面,打开git bash.输入ssh [email protected](这里是你局域网的ip地址,如果不知道多少的话可以在虚拟机里面ifconfig查看一下),windows可以连接到虚拟机的前提是VirtualBox的网络选择了桥接的模式。

在这里插入图片描述然后,在刚装好虚拟机之后,我们会建议大家把虚拟机里面的源更新(/etc/apt/source.list),这里我使用的是中科大的源文件。

deb http://mirrors.ustc.edu.cn/debian/ buster main
deb-src http://mirrors.ustc.edu.cn/debian/ buster main

deb http://security.debian.org/debian-security buster/updates main
deb-src http://security.debian.org/debian-security buster/updates main

# buster-updates, previously known as 'volatile'
deb http://mirrors.ustc.edu.cn/debian/ buster-updates main
deb-src http://mirrors.ustc.edu.cn/debian/ buster-updates main

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable
# deb-src [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable

然后,使用apt-get update来进行更新。

三、着手安装docker

1移除老版本docker

apt-get remove docker docker-engine docker.io

2.使用APT安装
由于 apt 源使用 HTTPS 以确保软件下载过程中不被篡改。因此,我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书。

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

3.添加GPG key
为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥

 curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/
gpg | apt-key add -

4.安装稳定的docker源
向 source.list 中添加 Docker CE 软件

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

Debian 7 需要进行额外的操作:
编辑 /etc/apt/sources.list 将 deb-src 一行删除或者使用 # 注释。

deb-src [arch=amd64] https://download.docker.com/linux/debian wh
eezy stable

5.安装docker ce
更新apt软件包缓存,并且安装docker-ce

apt-get update
apt-get install docker-ce

6.镜像加速器
为了能使大家更高几率的把docker跑起来,强烈建议在这里大家使用docker镜像加速器。具体操作是,在/etc/docker/目录下面,新建一个daemon.json文件(如果有的话,直接编译即可)在里面输入

{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://hub-mirror.c.163.com"
  ]
}

7.启动docker服务

systemctl enable docker
systemctl daemon-reload
systemctl start docker

然后,我们可以通过

systemctl status docker

来查看docker的运行状态,
在这里插入图片描述看到这样的结果,说明docker已经正常跑起来了。

8.测试docker是否成功
输入docker run hello-world,如果看到下面的结果说明,已经docker安装成功
在这里插入图片描述

至此docker在Debian下面正式安装成功,大家在安装的过程中有其它文件,可以给我留言,也可以私信我。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章