Centos环境docker的正确安装及疑难杂症
根據(jù)官方文檔:https://docs.docker.com/install/linux/docker-ce/centos/搭建docker?
1.卸載docker舊版本:
2.安裝相關(guān)工具類:
sudo yum install -y yum-utils \device-mapper-persistent-data \lvm23.配置docker倉庫:
sudo yum-config-manager \--add-repo \https://download.docker.com/linux/centos/docker-ce.repo 會(huì)報(bào)以下錯(cuò)誤: Loaded plugins: fastestmirror 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 Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo : [Errno 14] curl#35 - "TCP connection reset by peer這是由于國內(nèi)訪問不到docker官方鏡像的緣故?
可以通過aliyun的源來完成:
4.安裝docker
sudo yum install docker-ce 出現(xiàn)以下異常: Loaded plugins: fastestmirror base https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#35 - "TCP connection reset by peer" Trying other mirror.One of the configured repositories failed (Docker CE Stable - x86_64),and yum doesn't have enough cached data to continue. At this point the onlysafe thing yum can do is fail. There are a few ways to work "fix" this:1. Contact the upstream for the repository and get them to fix the problem.2. Reconfigure the baseurl/etc. for the repository, to point to a workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=docker-ce-stable ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable docker-ce-stableorsubscription-manager repos --disable=docker-ce-stable5. Configure the failing repository to be skipped, if it is unavailable.Note that yum will try to contact the repo. when it runs most commands,so will have to try and fail each time (and thus. yum will be be muchslower). If it is a very temporary problem though, this is often a nicecompromise:yum-config-manager --save --setopt=docker-ce-stable.skip_if_unavailable=truefailure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try. https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#35 - "TCP connection reset by peer"分析原因?yàn)?#xff1a;阿里的鏡像庫文件也指向docker官方庫,所以需要修改庫文件
sudo vim /etc/yum.repos.d/docker-ce.repo通過命令把https://download-stage.docker.com替換為http://mirrors.aliyun.com/docker-ce
命令如下::%s#https://download-stage.docker.com#http://mirrors.aliyun.com/docker-ce#g
再執(zhí)行docker的安裝命令即可安裝成功。
sudo yum install docker-ce內(nèi)容如下:
Installed:docker-ce.x86_64 0:18.03.0.ce-1.el7.centosDependency Installed:audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7 container-selinux.noarch 2:2.42-1.gitad8f0f7.el7 libcgroup.x86_64 0libtool-ltdl.x86_64 0:2.4.2-22.el7_3 pigz.x86_64 0:2.3.3-1.el7.centos policycoreutils-python.x86_64 0:2.5-17.1.el7 python-IPy.noarchComplete!5.驗(yàn)證docker安裝成功:
啟動(dòng)docker:
sudo systemctl start docker驗(yàn)證docker:
sudo docker run hello-world則會(huì)出現(xiàn)以下異常:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9bb5a5d4561a: Pulling fs layer docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18e See 'docker run --help'.此錯(cuò)誤也是網(wǎng)絡(luò)問題:出現(xiàn)這個(gè)問題原因?yàn)閲鴥?nèi)網(wǎng)絡(luò)問題,無法連接到 docker hub。?
配置阿里云的docker鏡像庫:在阿里云開通容器鏡像服務(wù)拿到加速地址在執(zhí)行以下命令:
也可以:
好在國內(nèi)已經(jīng)有 ?daocloud,docker指定該源即可。
vi /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target[Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --registry-mirror=http://f2d6cb40.m.daocloud.io ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s[Install] WantedBy=multi-user.target重啟docker服務(wù):
$ sudo systemctl daemon-reload $ sudo systemctl restart docker?
再次驗(yàn)證docker:
sudo docker run hello-world出現(xiàn)一下內(nèi)容表示驗(yàn)證成功:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9bb5a5d4561a: Pull complete Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77 Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/ For more examples and ideas, visit:https://docs.docker.com/engine/userguide/?
轉(zhuǎn)載于:https://www.cnblogs.com/liuyansheng/p/9203134.html
總結(jié)
以上是生活随笔為你收集整理的Centos环境docker的正确安装及疑难杂症的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

- 上一篇: contos LINUX搭建LAMP笔记
- 下一篇: BZOJ 1603: [Usaco200