CentOS7環境下安裝docker

操作系統 : CentOS7.5.1804_x64

docker版本: docker-ce-18.06.3

準備環境

1、如之前安裝過移除老舊版本

yum remove docker docker-client docker-client-latest docker-common docker-latest \
    docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

2、使用阿里鏡像庫安裝

# 安裝必要的一些系統工具
yum install -y yum-utils device-mapper-persistent-data lvm2

# 添加軟件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 更新cache
yum makecache fast

安裝docker

1、安裝

# 查看所有倉庫中所有docker版本,並選擇特定版本安裝
yum list docker-ce --showduplicates | sort -r

# 安裝docker(這裏選擇 18.06.3 版本)
yum install -y docker-ce-18.06.3.ce-3.el7

2、啓動

# 啓動
systemctl start docker
# 開機啓動
systemctl enable docker

3、驗證是否安裝成功

[root@host26 ~]# docker version
Client:
 Version:           18.06.3-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        d7080c1
 Built:             Wed Feb 20 02:26:51 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@host26 ~]#

使用docker鏡像

1、配置鏡像加速

對應文件 : /etc/docker/daemon.json

沒有則創建,內容如下:

{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://reg-mirror.qiniu.com"
  ]
}

重新啓動服務

systemctl daemon-reload &&  systemctl restart docker

檢查加速器是否生效

執行 docker info 命令,如果從結果中看到了如下內容,說明配置成功。

Registry Mirrors:
 https://dockerhub.azk8s.cn/
 https://reg-mirror.qiniu.com/
Live Restore Enabled: false

2、使用鏡像

獲取鏡像,示例如下:

[root@host26 dk]# docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
5667fdb72017: Pull complete
d83811f270d5: Pull complete
ee671aafb583: Pull complete
7fc152dfb3a6: Pull complete
Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
Status: Downloaded newer image for ubuntu:18.04
[root@host26 dk]# ls
[root@host26 dk]# ll -h
total 0
[root@host26 dk]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              18.04               2ca708c1c9cc        6 days ago          64.2MB
[root@host26 dk]#

使用鏡像,示例如下:

[root@host26 dk]# docker run -t -i ubuntu:18.04 /bin/bash
root@6c1d0cdbbaaf:/# cat /etc/issue
Ubuntu 18.04.3 LTS \n \l

root@6c1d0cdbbaaf:/#

參數說明:

-i: 交互式操作。
-t: 終端。
ubuntu:18.04 : 這是指用 ubuntu 18.04 版本鏡像爲基礎來啓動容器。
/bin/bash:放在鏡像名後的是命令,這裏我們希望有個交互式 Shell,因此用的是 /bin/bash。

 本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20191117_CentOS7環境下安裝docker.rst

歡迎補充

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