Centos 7下Docker的安装与非root配置

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. CentOS 7下docker的安装

# 1. install yum-utils
$ sudo yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
base                                                                                          | 3.6 kB  00:00:00
epel                                                                                          | 4.3 kB  00:00:00
extras                                                                                        | 3.4 kB  00:00:00
update                                                                                        | 3.4 kB  00:00:00
(1/3): epel/7/x86_64/updateinfo                                                               | 797 kB  00:00:00
(2/3): epel/7/x86_64/primary_db                                                               | 4.7 MB  00:00:00
(3/3): update/7/x86_64/primary_db                                                             | 4.8 MB  00:00:00
Loading mirror speeds from cached hostfile
Package yum-utils-1.1.31-40.el7.noarch already installed and latest version
Nothing to do

# 2. set up the stable repository
$sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

# 3. install docker
$ sudo yum install docker-ce
Loaded plugins: fastestmirror, langpacks
docker-ce-stable                                                                              | 2.9 kB  00:00:00
docker-ce-stable/x86_64/primary_db                                                            | 4.8 kB  00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:17.03.1.ce-1.el7.centos will be installed
--> Processing Dependency: docker-ce-selinux >= 17.03.1.ce-1.el7.centos for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
--> Processing Dependency: libcgroup for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
--> Running transaction check
---> Package docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos will be installed
--> Processing Dependency: policycoreutils-python for package: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch
---> Package libcgroup.x86_64 0:0.41-11.el7 will be installed
---> Package libseccomp.x86_64 0:2.3.1-2.el7 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-11.el7_3 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-1 for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-5 for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 will be installed
---> Package checkpolicy.x86_64 0:2.5-4.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-5.1.el7_3 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                         Arch            Version                             Repository                 Size
=====================================================================================================================
Installing:
 docker-ce                       x86_64          17.03.1.ce-1.el7.centos             docker-ce-stable           19 M
Installing for dependencies:
 audit-libs-python               x86_64          2.6.5-3.el7_3.1                     update                     70 k
 checkpolicy                     x86_64          2.5-4.el7                           base                      290 k
 docker-ce-selinux               noarch          17.03.1.ce-1.el7.centos             docker-ce-stable           28 k
 libcgroup                       x86_64          0.41-11.el7                         base                       65 k
 libseccomp                      x86_64          2.3.1-2.el7                         base                       56 k
 libsemanage-python              x86_64          2.5-5.1.el7_3                       update                    104 k
 policycoreutils-python          x86_64          2.5-11.el7_3                        update                    445 k
 python-IPy                      noarch          0.75-6.el7                          base                       32 k
 setools-libs                    x86_64          3.3.8-1.1.el7                       base                      612 k

Transaction Summary
=====================================================================================================================
Install  1 Package (+9 Dependent packages)

Total download size: 20 M
Installed size: 24 M
Is this ok [y/d/N]: y
Downloading packages:
(1/10): audit-libs-python-2.6.5-3.el7_3.1.x86_64.rpm                                          |  70 kB  00:00:00
(2/10): checkpolicy-2.5-4.el7.x86_64.rpm                                                      | 290 kB  00:00:00
(3/10): libseccomp-2.3.1-2.el7.x86_64.rpm                                                     |  56 kB  00:00:00
(4/10): libcgroup-0.41-11.el7.x86_64.rpm                                                      |  65 kB  00:00:00
(5/10): policycoreutils-python-2.5-11.el7_3.x86_64.rpm                                        | 445 kB  00:00:00
(6/10): setools-libs-3.3.8-1.1.el7.x86_64.rpm                                                 | 612 kB  00:00:00
(7/10): libsemanage-python-2.5-5.1.el7_3.x86_64.rpm                                           | 104 kB  00:00:00
(8/10): python-IPy-0.75-6.el7.noarch.rpm                                                      |  32 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm is not installed
(9/10): docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm                                  |  28 kB  00:00:00
(10/10): docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm                                         |  19 MB  00:00:00
---------------------------------------------------------------------------------------------------------------------
Total                                                                                 23 MB/s |  20 MB  00:00:00
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libcgroup-0.41-11.el7.x86_64                                                                     1/10
  Installing : setools-libs-3.3.8-1.1.el7.x86_64                                                                2/10
  Installing : checkpolicy-2.5-4.el7.x86_64                                                                     3/10
  Installing : libsemanage-python-2.5-5.1.el7_3.x86_64                                                          4/10
  Installing : audit-libs-python-2.6.5-3.el7_3.1.x86_64                                                         5/10
  Installing : python-IPy-0.75-6.el7.noarch                                                                     6/10
  Installing : policycoreutils-python-2.5-11.el7_3.x86_64                                                       7/10
  Installing : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch                                                 8/10
setsebool:  SELinux is disabled.
libsemanage.semanage_direct_install_info: Overriding docker module at lower priority 100 with module at priority 400.
  Installing : libseccomp-2.3.1-2.el7.x86_64                                                                    9/10
  Installing : docker-ce-17.03.1.ce-1.el7.centos.x86_64                                                        10/10
  Verifying  : libseccomp-2.3.1-2.el7.x86_64                                                                    1/10
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                     2/10
  Verifying  : audit-libs-python-2.6.5-3.el7_3.1.x86_64                                                         3/10
  Verifying  : libsemanage-python-2.5-5.1.el7_3.x86_64                                                          4/10
  Verifying  : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch                                                 5/10
  Verifying  : libcgroup-0.41-11.el7.x86_64                                                                     6/10
  Verifying  : policycoreutils-python-2.5-11.el7_3.x86_64                                                       7/10
  Verifying  : docker-ce-17.03.1.ce-1.el7.centos.x86_64                                                         8/10
  Verifying  : checkpolicy-2.5-4.el7.x86_64                                                                     9/10
  Verifying  : setools-libs-3.3.8-1.1.el7.x86_64                                                               10/10

Installed:
  docker-ce.x86_64 0:17.03.1.ce-1.el7.centos

Dependency Installed:
  audit-libs-python.x86_64 0:2.6.5-3.el7_3.1                    checkpolicy.x86_64 0:2.5-4.el7
  docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos            libcgroup.x86_64 0:0.41-11.el7
  libseccomp.x86_64 0:2.3.1-2.el7                               libsemanage-python.x86_64 0:2.5-5.1.el7_3
  policycoreutils-python.x86_64 0:2.5-11.el7_3                  python-IPy.noarch 0:0.75-6.el7
  setools-libs.x86_64 0:3.3.8-1.1.el7

Complete!

# 4. start docker
$ sudo systemctl start docker

# 5. verify docker
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

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.
 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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

2. docker非root配置

# 查看是否存在docker用户组
$ cat /etc/group | grep docker

# 如果不存在docker用户组,则创建
$ sudo groupadd docker

# 添加当前用户到docker组中
$ sudo gpasswd -a ${USER} docker

# 重启docker
$ sudo systemctl restart docker
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,544评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,430评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,764评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,193评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,216评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,182评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,063评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,917评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,329评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,543评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,722评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,425评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,019评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,671评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,825评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,729评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,614评论 2 353

推荐阅读更多精彩内容