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下面正式安裝成功,大家在安裝的過程中有其它文件,可以給我留言,也可以私信我。

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