centos7安裝docker,小白向
- centos7安裝docker
-
- 準備
- 安裝
- 驗證與使用
-
- 驗證docker是否安裝成功
- 使用
centos7安裝docker
近期在堂姐(九點澡堂子)那白嫖了一年阿裡雲伺服器,于是準備利用起來搭建個個人網站,由于伺服器配置比較低,也因為有點懶是以多數元件打算使用docker安裝,也記錄一下這整個過程
第一站,安裝docker
準備
因為我習慣在root使用者下操作,是以以下都是在root下做的,如果不喜歡自行更換,大差不差
首先要明确自己的系統版本支援docker,Docker 要求 CentOS 系統的核心版本高于 3.10,可以使用
uname -r
指令來檢視自己的系統核心版本。我這裡用的是centos7。
其次如果已經安裝過docker的,想要重裝或者覺得docker版本太低可以解除安裝重裝。
yum remove docker docker-common docker-selinux docker-engine
最後,安裝工具包
yum-utils
yum install -y yum-utils
安裝
1.配置yum源
建議選擇國内的源,速度會快一些,此處選擇阿裡雲的
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2.檢視所有docker版本
yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
docker-ce.x86_64 3:20.10.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.6-3.el7 @docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.1-3.el7 docker-ce-stable
...
從中可以看到很多個版本,可從中選擇任一安裝
3.安裝
可以從上面中任選一個版本指定安裝,将以下
<VERSION_STRING>
替換成對應版本即可
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
也可以通過不指定版本直接安裝最新版
yum install docker-ce docker-ce-cli containerd.io
4.啟動
systemctl start docker
驗證與使用
驗證docker是否安裝成功
1.檢視docker版本
docker version
2.運作官方提供的驗證鏡像
helloworld
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即為安裝成功
使用
docker的基本使用及指令等未完待續