liunx下安装Docker

1、安装并启动docker

1、检查内核版本,必须是3.10及以上
uname -r
2、安装docker

yum install docker命令安装(需要联网)

 1 [root@localhost ~]# yum install docker
 2 Loaded plugins: fastestmirror
 3 base                                                                                                                                                                   | 3.6 kB  00:00:00     
 4 extras                                                                                                                                                                 | 3.4 kB  00:00:00     
 5 updates                                                                                                                                                                | 3.4 kB  00:00:00     
 6 (1/4): extras/7/x86_64/primary_db                                                                                                                                      | 156 kB  00:00:00     
 7 (2/4): updates/7/x86_64/primary_db                                                                                                                                     | 1.3 MB  00:00:00     
 8 (3/4): base/7/x86_64/group_gz                                                                                                                                          | 166 kB  00:00:00     
 9 (4/4): base/7/x86_64/primary_db                                                                                                                                        | 6.0 MB  00:00:01     
10 Determining fastest mirrors
11  * base: centos.ustc.edu.cn
12  * extras: mirrors.163.com
13  * updates: centos.ustc.edu.cn
14 Resolving Dependencies
15 --> Running transaction check
16 ---> Package docker.x86_64 2:1.13.1-88.git07f3374.el7.centos will be installed
17 --> Processing Dependency: docker-common = 2:1.13.1-88.git07f3374.el7.centos for package: 2:docker-1.13.1-88.git07f3374.el7.centos.x86_64
18 --> Processing Dependency: docker-client = 2:1.13.1-88.git07f3374.el7.centos for package: 2:docker-1.13.1-88.git07f3374.el7.centos.x86_64
19 ...
20 Install  1 Package (+27 Dependent packages)
21 Upgrade  1 Package (+15 Dependent packages)
22 
23 Total download size: 41 M
24 
25 询问是否下载安装,输入y
26 Is this ok [y/d/N]: y
27 进入下载安装过程...
28 Downloading packages:
29 Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
30 warning: /var/cache/yum/x86_64/7/extras/packages/atomic-registries-1.22.1-26.gitb507039.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEYs |    0 B  --:--:-- ETA 
31 Public key for atomic-registries-1.22.1-26.gitb507039.el7.centos.x86_64.rpm is not installed
32 (1/44): atomic-registries-1.22.1-26.gitb507039.el7.centos.x86_64.rpm                                                                                                   |  35 kB  00:00:00     
33 Public key for PyYAML-3.10-11.el7.x86_64.rpm is not installed
34 (2/44): PyYAML-3.10-11.el7.x86_64.rpm                                                                                                                                  | 153 kB  00:00:00     
35 (3/44): audit-2.8.4-4.el7.x86_64.rpm                                                                                                                                   | 250 kB  00:00:00     
36 ...
37 (44/44): systemd-sysv-219-62.el7.x86_64.rpm                                                                                                                            |  83 kB  00:00:01     
38 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 Total  
40 安装完成后可能出现下面内容(大致是从文件中检索秘钥,询问是否导入秘钥),输入y即可
41 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
42 Importing GPG key 0xF4A80EB5:
43  Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
44  Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
45  Package    : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
46  From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
47 Is this ok [y/N]: y
View Code

3、输入y确认安装
4、启动docker

  启动docker
1
[root@localhost ~]# systemctl start docker
  查看docker版本 2 [root@localhost ~]# docker -v
  Docker version 1.12.6, build 3e8e77d/1.12.6

2.可能出现的错误

错误1:

  启动时提示报错

    Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

  根据提示查看 systemctl status docker.service,看到错误信息如下

    Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a ne...led=false)

 1 [root@localhost ~]# systemctl start docker
 2 Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
 3 [root@localhost ~]# systemctl status docker.service
 4 ● docker.service - Docker Application Container Engine
 5    Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
 6    Active: failed (Result: exit-code) since Sat 2018-12-29 02:40:04 EST; 2min 11s ago
 7      Docs: http://docs.docker.com
 8   Process: 4936 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
 9  Main PID: 4936 (code=exited, status=1/FAILURE)
10    CGroup: /system.slice/docker.service
11 
12 Dec 29 02:40:02 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
13 Dec 29 02:40:02 localhost.localdomain dockerd-current[4936]: time="2018-12-29T02:40:02.948680364-05:00" level=warning msg="could not change group /var/run/docker.sock to docker:...not found"
14 Dec 29 02:40:02 localhost.localdomain dockerd-current[4936]: time="2018-12-29T02:40:02.956633687-05:00" level=info msg="libcontainerd: new containerd process, pid: 4940"
15 Dec 29 02:40:03 localhost.localdomain dockerd-current[4936]: time="2018-12-29T02:40:03.969576324-05:00" level=warning msg="overlay2: the backing xfs filesystem is formatted without d_type...
16 Dec 29 02:40:04 localhost.localdomain dockerd-current[4936]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a ne...led=false)
17 Dec 29 02:40:04 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
18 Dec 29 02:40:04 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
19 Dec 29 02:40:04 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
20 Dec 29 02:40:04 localhost.localdomain systemd[1]: docker.service failed.
21 Hint: Some lines were ellipsized, use -l to show in full.

在上面报错中可以看到启动出错的原因
Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a ne...led=false)

 

 

解决方案

重新编辑/etc/sysconfig/docker(docker配置文件)

 1 [root@localhost ~]# vi /etc/sysconfig/docker
 2 # /etc/sysconfig/docker
 3 
 4 # Modify these options if you want to change the way the docker daemon runs
 5 OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
 6 if [ -z "${DOCKER_CERT_PATH}" ]; then
 7     DOCKER_CERT_PATH=/etc/docker
 8 fi
 9 
10 # Do not add registries in this file anymore. Use /etc/containers/registries.conf
11 # instead. For more information reference the registries.conf(5) man page.
12 
13 # Location used for temporary files, such as those created by
14 # docker load and build operations. Default is /var/lib/docker/tmp
15 # Can be overriden by setting the following environment variable.
16 # DOCKER_TMPDIR=/var/tmp
17 
18 # Controls the /etc/cron.daily/docker-logrotate cron job status.
19 # To disable, uncomment the line below.
20 
21 将上面的
22 OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
23 修改为
24 OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false'

然后退出vi编辑(按Esc键,输入:wq,按Enter)

输入systemctl restart docker命令重启docker服务

 

猜你喜欢

转载自www.cnblogs.com/shenzs-whj/p/10196933.html