安装Docker

docker分为两个版本: Docker CE 和 Docker EE。Docker CE 即社区免费版,Docker EE 即企业版,强调安全,但需付费使用。常用开源的使用主要以Docker CE 为主。以下是在centos7.4下进行安装的。

1.Docker的安装条件

安装Docker 要求 CentOS 系统的内核版本高于 3.10 ,就需要对内核版本进行查看,这样做是保证前提条件:CentOS 版本是否支持 Docker运行 。通过 uname -r 命令查看你当前的内核版本

[jhadmin@localhost ~]$ uname -r
3.10.0-693.el7.x86_64

2.Docker的安装依赖配置

在保证用户具有管理权限下进行操作:

    [root@localhost jhadmin]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    Installed:
      yum-utils.noarch 0:1.1.31-50.el7                                                                                                              
    
    Dependency Installed:
      libxml2-python.x86_64 0:2.9.1-6.el7_2.3          python-chardet.noarch 0:2.2.1-1.el7_1          python-kitchen.noarch 0:1.1.1-5.el7         
    
    Updated:
      device-mapper-persistent-data.x86_64 0:0.7.3-3.el7                              lvm2.x86_64 7:2.02.180-10.el7_6.3                             
    
    Dependency Updated:
      device-mapper.x86_64 7:1.02.149-10.el7_6.3                                device-mapper-event.x86_64 7:1.02.149-10.el7_6.3                    
      device-mapper-event-libs.x86_64 7:1.02.149-10.el7_6.3                     device-mapper-libs.x86_64 7:1.02.149-10.el7_6.3                     
      lvm2-libs.x86_64 7:2.02.180-10.el7_6.3           

3.添加软件源信息

    sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost jhadmin]# sudo yum makecache fast
Loaded plugins: fastestmirror
base                                                                                                                     | 3.6 kB  00:00:00 

4. 更新 yum 缓存:

sudo yum makecache fast
Loaded plugins: fastestmirror
base                                                                                                                     | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                         | 3.5 kB  00:00:00     
http://mirrors.cqu.edu.cn/CentOS/7.6.1810/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
extras                                                                                                                   | 3.4 kB  00:00:00     
updates                                                                                                                  | 3.4 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/updateinfo                                                                                |   55 B  00:00:00     
(2/2): docker-ce-stable/x86_64/primary_db    

5.安装Docker ce

sudo yum -y install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.3-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.3-3.el7.x86_64

6.启动 Docker 后台服务

sudo systemctl start docker

7.测试运行 hello-world

[root@runoob ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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.
    (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:

8.查看Docker是否安装,是否存在Docker进程项目启动

[root@localhost jhadmin]# ps -ef|grep docker
root      2446     1  0 21:52 ?        00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root      2708  1369  0 22:08 pts/0    00:00:00 grep --color=auto docker

[root@localhost jhadmin]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


用docker stop (CONTAINER ID号) 停止Docker中允许的进程

docker stop  (CONTAINER ID)
docker stop (NAMES)
上一篇:Linux系统下安装jdk


下一篇:yum 下载全量依赖 rpm 包及离线安装(终极解决方案)