CentOS7.2 上安装 Docker 教程

511遇见

1、centos7.0+中Docker 软件包已经包括在默认的 CentOS-Extras 软件源里

因此想要安装 docker,只需要运行下面的 yum 命令:

[root@localhost ~]#  yum install docker

一路 Y
安装成功返回

Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
nginx                                                    | 2.9 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/2): extras/7/x86_64/primary_db                          | 160 kB   00:00     
(2/2): updates/7/x86_64/primary_db                         | 6.5 MB   00:11     
Determining fastest mirrors
 * base: mirrors.sina.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.sina.cn
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:1.10.3-46.el7.centos.10 will be installed
--> Processing Dependency: docker-common = 1.10.3-46.el7.centos.10 for package: docker-1.10.3-46.el7.centos.10.x86_64
--> Processing Dependency: oci-systemd-hook >= 1:0.1.4-4 for package: docker-1.10.3-46.el7.centos.10.x86_64
--> Processing Dependency: oci-register-machine >= 1:0-1.7 for package: docker-1.10.3-46.el7.centos.10.x86_64
--> Processing Dependency: docker-selinux >= 1.10.3-46.el7.centos.10 for package: docker-1.10.3-46.el7.centos.10.x86_64
--> Running transaction check
---> Package docker-common.x86_64 0:1.10.3-46.el7.centos.10 will be installed
---> Package docker-selinux.x86_64 0:1.10.3-46.el7.centos.10 will be installed
---> Package oci-register-machine.x86_64 1:0-1.7.git31bbcd2.el7 will be installed
---> Package oci-systemd-hook.x86_64 1:0.1.4-4.git41491a3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                 Arch      Version                      Repository
                                                                           Size
================================================================================
Installing:
 docker                  x86_64    1.10.3-46.el7.centos.10      extras    9.5 M
Installing for dependencies:
 docker-common           x86_64    1.10.3-46.el7.centos.10      extras     61 k
 docker-selinux          x86_64    1.10.3-46.el7.centos.10      extras     78 k
 oci-register-machine    x86_64    1:0-1.7.git31bbcd2.el7       extras    929 k
 oci-systemd-hook        x86_64    1:0.1.4-4.git41491a3.el7     extras     27 k

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

Total download size: 11 M
Installed size: 48 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): docker-common-1.10.3-46.el7.centos.10.x86_64.rpm    |  61 kB   00:00     
(2/5): oci-systemd-hook-0.1.4-4.git41491a3.el7.x86_64.rpm  |  27 kB   00:00     
(3/5): docker-selinux-1.10.3-46.el7.centos.10.x86_64.rpm   |  78 kB   00:02     
(4/5): oci-register-machine-0-1.7.git31bbcd2.el7.x86_64.rp | 929 kB   00:03     
(5/5): docker-1.10.3-46.el7.centos.10.x86_64.rpm           | 9.5 MB   00:09     
--------------------------------------------------------------------------------
Total                                              1.2 MB/s |  11 MB  00:09     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:oci-register-machine-0-1.7.git31bbcd2.el7.x86_64           1/5 
  Installing : docker-selinux-1.10.3-46.el7.centos.10.x86_64                2/5 
  Installing : 1:oci-systemd-hook-0.1.4-4.git41491a3.el7.x86_64             3/5 
  Installing : docker-common-1.10.3-46.el7.centos.10.x86_64                 4/5 
  Installing : docker-1.10.3-46.el7.centos.10.x86_64                        5/5 
  Verifying  : docker-common-1.10.3-46.el7.centos.10.x86_64                 1/5 
  Verifying  : docker-1.10.3-46.el7.centos.10.x86_64                        2/5 
  Verifying  : 1:oci-systemd-hook-0.1.4-4.git41491a3.el7.x86_64             3/5 
  Verifying  : docker-selinux-1.10.3-46.el7.centos.10.x86_64                4/5 
  Verifying  : 1:oci-register-machine-0-1.7.git31bbcd2.el7.x86_64           5/5 

Installed:
  docker.x86_64 0:1.10.3-46.el7.centos.10                                       

Dependency Installed:
  docker-common.x86_64 0:1.10.3-46.el7.centos.10                                
  docker-selinux.x86_64 0:1.10.3-46.el7.centos.10                               
  oci-register-machine.x86_64 1:0-1.7.git31bbcd2.el7                            
  oci-systemd-hook.x86_64 1:0.1.4-4.git41491a3.el7                              

Complete!

2、启动 Docker 服务

安装完成后,使用下面的命令来启动 docker 服务,

[root@localhost ~]# service docker start

返回:

Redirecting to /bin/systemctl start  docker.service

将其设置为开机启动:

[root@localhost ~]# chkconfig docker on

3、下载官方的 CentOS 镜像到本地

镜像下载比较慢,要耐心的等待...

[root@localhost ~]# docker pull centos

返回:

Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
3d8673bd162a: Pull complete 
Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
Status: Downloaded newer image for docker.io/centos:latest

4、确认 CentOS 镜像已经被获取:

[root@localhost ~]#  docker images centos

返回:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              970633036444        2 weeks ago         196.7 MB

5、运行一个 Docker 容器:

[root@localhost ~]# docker run -i -t centos /bin/bash
[root@8f304ef2e3a0 /]# 

我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。

[root@localhost ~]# docker run -i -t centos /bin/bash
[root@8f304ef2e3a0 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
[root@8f304ef2e3a0 /]# exit
exit
[root@localhost ~]# 

6、搜索基于 Fedora 和 Ubuntu 操作系统的容器

搜索Fedora

[root@localhost ~]# docker search ubuntu

返回:

INDEX       NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/ubuntu                     Ubuntu is a Debian-based Linux operating s...   4473      [OK]       
docker.io   docker.io/ubuntu-upstart             Upstart is an event-based replacement for ...   65        [OK]       
docker.io   docker.io/rastasheep/ubuntu-sshd     Dockerized SSH service, built on top of of...   31                   [OK]
docker.io   docker.io/torusware/speedus-ubuntu   Always updated official Ubuntu docker imag...   27                   [OK]
docker.io   docker.io/ubuntu-debootstrap         debootstrap --variant=minbase --components...   25        [OK]       
docker.io   docker.io/nickistre/ubuntu-lamp      LAMP server on Ubuntu                           8                    [OK]
docker.io   docker.io/nuagebec/ubuntu            Simple always updated Ubuntu docker images...   7                    [OK]
docker.io   docker.io/nimmis/ubuntu              This is a docker images different LTS vers...   5                    [OK]
docker.io   docker.io/maxexcloo/ubuntu           Docker base image built on Ubuntu with Sup...   2                    [OK]
docker.io   docker.io/admiringworm/ubuntu        Base ubuntu images based on the official u...   1                    [OK]
docker.io   docker.io/darksheer/ubuntu           Base Ubuntu Image -- Updated hourly             1                    [OK]
docker.io   docker.io/jordi/ubuntu               Ubuntu Base Image                               1                    [OK]
docker.io   docker.io/seetheprogress/ubuntu      Ubuntu image provided by seetheprogress us...   1                    [OK]
docker.io   docker.io/croscon/ubuntu             Crosconized Ubuntu                              0                    [OK]
docker.io   docker.io/datenbetrieb/ubuntu        custom flavor of the official ubuntu base ...   0                    [OK]
docker.io   docker.io/dorapro/ubuntu             ubuntu image                                    0                    [OK]
docker.io   docker.io/esycat/ubuntu              Ubuntu LTS                                      0                    [OK]
docker.io   docker.io/konstruktoid/ubuntu        Ubuntu base image                               0                    [OK]
docker.io   docker.io/life360/ubuntu             Ubuntu is a Debian-based Linux operating s...   0                    [OK]
docker.io   docker.io/lynxtp/ubuntu              https://github.com/lynxtp/docker-ubuntu         0                    [OK]
docker.io   docker.io/smartentry/ubuntu          ubuntu with smartentry                          0                    [OK]
docker.io   docker.io/teamrock/ubuntu            TeamRock's Ubuntu image configured with AW...   0                    [OK]
docker.io   docker.io/ustclug/ubuntu             ubuntu image for docker with USTC mirror        0                    [OK]
docker.io   docker.io/webhippie/ubuntu           Docker images for ubuntu                        0                    [OK]
docker.io   docker.io/widerplan/ubuntu           Our basic Ubuntu images.                        0                    [OK]

搜索基于Ubuntu

[root@localhost ~]# docker search fedora

返回:

INDEX       NAME                                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/fedora                         Official Docker builds of Fedora                406       [OK]       
docker.io   docker.io/dockingbay/fedora-rust         Trusted build of Rust programming language...   3                    [OK]
docker.io   docker.io/gluster/gluster-fedora         Official GlusterFS image [ Fedora 21 + Glu...   3                    [OK]
docker.io   docker.io/eminguez/transmission-fedora   Transmission Fedora (fedora:latest) docker...   2                    [OK]
docker.io   docker.io/startx/fedora                  Simple container used for all startx based...   2                    [OK]
docker.io   docker.io/dasrick/fedora-nginx           NGINX image - port 80, 443 - based on Fedo...   1                    [OK]
docker.io   docker.io/mattsch/fedora-rpmfusion       Base container for Fedora with RPM Fusion ...   1                    [OK]
docker.io   docker.io/neroinc/fedora-apache          Plain and simple image with Apache httpd b...   1                    [OK]
docker.io   docker.io/pacur/fedora-22                Pacur Fedora 22                                 1                    [OK]
docker.io   docker.io/cloudrunnerio/fedora                                                           0                    [OK]
docker.io   docker.io/kino/fedora                    fedora base                                     0                    [OK]
docker.io   docker.io/krystalcode/fedora             Fedora base image that includes some addit...   0                    [OK]
docker.io   docker.io/mattsch/fedora-couchpotato     Fedora Couchpotato                              0                    [OK]
docker.io   docker.io/mattsch/fedora-htpc            Fedora HTPC                                     0                    [OK]
docker.io   docker.io/mattsch/fedora-nzbget          Fedora NZBGet                                   0                    [OK]
docker.io   docker.io/mattsch/fedora-nzbhydra        Fedora NZBHydra                                 0                    [OK]
docker.io   docker.io/mattsch/fedora-plex            Fedora Plex                                     0                    [OK]
docker.io   docker.io/mattsch/fedora-plexpy          Fedora PlexPy Container                         0                    [OK]
docker.io   docker.io/mattsch/fedora-sonarr          Fedora Sonarr                                   0                    [OK]
docker.io   docker.io/mattsch/fedora-transmission    Fedora Transmission                             0                    [OK]
docker.io   docker.io/opencpu/fedora                 Stable version of opencpu for Fedora            0                    [OK]
docker.io   docker.io/qnib/fedora                    Base QNIBTerminal image of fedora               0                    [OK]
docker.io   docker.io/rocproject/ci-fedora           Continuous integration builds of Roc (Fedo...   0                    [OK]
docker.io   docker.io/smartentry/fedora              Fedora with smartentry                          0                    [OK]
docker.io   docker.io/ustclug/fedora                 fedora with USTC mirror                         0                    [OK]

7、卸载Docker

[root@localhost ~]# yum remove docke

说明

CentOS的版本不同,安装命令会有不同,返回的数据也会不同,所以要根据自己的版本,灵活测试,希望对你有所帮助。


发布日期:

所属分类: 手游单机 标签:  


没有相关文章!