Linux中修改docker鏡像源及安裝docker


 

1、首先備份系統自帶yum源配置文件/etc/yum.repos.d/CentOS-Base.repo

 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2、進入yum源配置文件所在的文件夾

cd /etc/yum.repos.d/

3、下載163的yum源配置文件(CentOS7)

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

清華大學鏡像源地址:https://mirrors.tuna.tsinghua.edu.cn/

4、清理緩存

yum clean all

5、測試下載安裝

yum install gcc

6、安裝docker

yum install docker

7、啟動

systemctl start docker

8、啟動報錯

[root@localhost yum.repos.d]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@localhost yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2018-12-12 07:27:23 UTC; 28s ago
     Docs: http://docs.docker.com
  Process: 4166 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)
 Main PID: 4166 (code=exited, status=1/FAILURE)

Dec 12 07:27:21 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
Dec 12 07:27:22 localhost.localdomain dockerd-current[4166]: time="2018-12-12T07:27:22.024162402Z" level=warning msg="could not change group /var/run/docker...t found"
Dec 12 07:27:22 localhost.localdomain dockerd-current[4166]: time="2018-12-12T07:27:22.038636556Z" level=info msg="libcontainerd: new containerd process, pid: 4170"
Dec 12 07:27:23 localhost.localdomain dockerd-current[4166]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. ...d=false)
Dec 12 07:27:23 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Dec 12 07:27:23 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Dec 12 07:27:23 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Dec 12 07:27:23 localhost.localdomain systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

根據提示查看一下詳情,執行:journalctl -xe

Dec 13 06:42:24 localhost.localdomain dockerd[2719]: time="2018-12-13T06:42:24.350020859Z" level=info msg="libcontainerd: new containerd process, pid: 2722"
Dec 13 06:42:25 localhost.localdomain dockerd[2719]: time="2018-12-13T06:42:25.356303658Z" level=error msg="[graphdriver] prior storage driver overlay2 failed: driver 
Dec 13 06:42:25 localhost.localdomain dockerd[2719]: Error starting daemon: error initializing graphdriver: driver not supported

錯誤原因:error initializing graphdriver: driver not supported
解決辦法:在 /etc/docker 目錄下創建daemon.json文件,並且加入以下配置

touch daemon.json
vi daemon.json
{
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

再次啟動

systemctl start docker

問題解決

 9、又來一個問題

Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot

此linux的內核中的SELinux不支持 overlay2 graph driver ,解決方法有兩個,要么啟動一個新內核,要么就在docker里禁用selinux,–selinux-enabled=false

vi /etc/sysconfig/docker

#設置
--selinux-enabled=false

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM