Centos环境docker的正确安装及疑难杂症

根据官方文档:https://docs.docker.com/install/linux/docker-ce/centos/搭建docker 
1.卸载docker旧版本:

sudo yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-selinux                   docker-engine-selinux                   docker-engine\

2.安装相关工具类:

sudo yum install -y yum-utils   device-mapper-persistent-data   lvm2

3.配置docker仓库:

sudo yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
会报以下错误:
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

这是由于国内访问不到docker官方镜像的缘故 
可以通过aliyun的源来完成:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
出现以下内容则表示docker仓库配置成功:
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

4.安装docker

sudo yum install docker-ce
出现以下异常:
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 only
 safe 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 working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=docker-ce-stable ...

     4. Disable the repository permanently, so yum won‘t use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable docker-ce-stable
        or
            subscription-manager repos --disable=docker-ce-stable

     5. 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 much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=docker-ce-stable.skip_if_unavailable=true

failure: 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"

分析原因为:阿里的镜像库文件也指向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

再执行docker的安装命令即可安装成功。

sudo yum install docker-ce

内容如下:

Installed:
  docker-ce.x86_64 0:18.03.0.ce-1.el7.centos

Dependency 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 0
  libtool-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.noarch

Complete!

5.验证docker安装成功:

启动docker:

sudo systemctl start docker

验证docker:

sudo docker run hello-world

则会出现以下异常:

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‘.

此错误也是网络问题:出现这个问题原因为国内网络问题,无法连接到 docker hub。 
配置阿里云的docker镜像库:在阿里云开通容器镜像服务拿到加速地址在执行以下命令:

也可以:

好在国内已经有  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服务:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

再次验证docker:

sudo docker run hello-world

出现一下内容表示验证成功:

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: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:
 $ docker run -it ubuntu bash

Share 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/

原文地址:https://www.cnblogs.com/liuyansheng/p/9203134.html

时间: 2024-10-08 21:31:32

Centos环境docker的正确安装及疑难杂症的相关文章

全网最详细的大数据集群环境下如何正确安装并配置多个不同版本的Cloudera Hue(图文详解)

不多说,直接上干货! 为什么要写这么一篇博文呢? 是因为啊,对于Hue不同版本之间,其实,差异还是相对来说有点大的,具体,大家在使用的时候亲身体会就知道了,比如一些提示和界面. 下载版本: cdh版本 http://archive-primary.cloudera.com/cdh5/cdh/5/ 假设,我已经安装了如下的一个Hue版本 具体,见 https://www.cnblogs.com/zlslch/category/996966.html 而,我现在,安装另一个Hue版本 下载需要的系统

CentOS 7 下 yum 方式安装 Docker 环境

教你如何在 CentOS 7 下 yum 方式安装 Docker 环境. 记录在CentOS 7下使用yum方式安装Docker环境的步骤. 1.移除旧版本: yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                  

Docker for Windows安装与Linux+PHP开发环境搭建(一)

Docker是什么? 简单得来说,Docker是一个由GO语言写的程序运行的"容器"(Linux containers, LXCs); 目前云服务的基石是操作系统级别的隔离,在同一台物理服务器上虚拟出多个主机.Docker则实现了一种应用程序级别的隔离; 它改变我们基本的开发.操作单元,由直接操作虚拟主机(VM),转换到操作程序运行的"容器"上来. Docker的好处 Docker的优点:运行快.部署敏捷.灵活.轻量.开源免费. Boot2Docker是一个专为Do

基于CentOS 7下最小化安装的操作系统搭建Zabbix3.0环境

环境说明 系统版本:CentOS Linux release 7.3.1611 (Core) 内核版本:3.10.0-514.el7.x86_64 Httpd版本:Apache/2.4.6 (CentOS) MariaDB版本:5.5.52-MariaDB PHP版本:PHP 5.4.16 环境准备 [[email protected] ~]# setenforce 0 [[email protected] ~]# sed -i "s/SELINUX=enforcing/SELINUX=disa

docker安装 之 ---CentOS 7 系统脚本自动安装

[使用脚本自动安装] 在测试或开发环境中Docker官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS系统上可以使用这套脚本安装: $ curl -fsSL get.docker.com -o get-docker.sh $ sudo sh get-docker.sh --mirror Aliyun 执行这个命令后,脚本就会自动的将一切准备工作做好,并且把Docker CE 的 edge版本安装在系统中. [启动 Docker CE] $ sudo systemctl enable d

CentOS7下如何正确安装并启动Docker(图文详解)

我使用了CentOS 7操作系统,可以非常容易地安装Docker环境.假设,下面我们都是用root用户进行操作,执行如下命令进行准备工作: yum install -y yum-utils yum-config-manager --add-repo https://docs.docker.com/engine/installation/linux/repo_files/centos/docker.repo yum makecache fast 上面首先安装了yum-utils,它提供了yum-c

Windows和Centos下Docker的安装配置

Windows和Centos下Docker的安装配置 windows环境下的安装(win10) 在Windows系统上需要利用toolbox来安装Docker,现在 Docker 有专门的 Win10 专业版系统的安装包,需要开启Hyper-V.然后才能正常安装 Hyper-V 就是虚拟机中的一种 开启Hyper-V win10专业版开启方式 键入win,搜索"windows"开打"启用或关闭windows功能",找到Hyper-V并勾选 win10家庭版开启方式

CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)

CentOS下使用yum命令 安装LAMP详细过程.我们使用的软件是CentOS的最新版本CentOS 6.3,其他版本的也基本类似. 第一步:更新系统内核(如果不想更新可以跳过本步). 首先更新系统内核到最新,因为最新版的CentOS 6.3的php版本为 5.3,早起版本的CentOS的php版本也比较低. 执行命令: yum -y update 注意:如果执行失败报错,可以执行修复命令: rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY* 第二步: 安装Ap

CentOS环境下R语言的安装和配置

最近在看数据统计和分析,想到了R语言,于是就着手在自己的CentOS环境下进行安装和配置.步骤如下: 1.前往R官网下载安装包. 2.解压压缩包:tar xvzf R-3.2.2.tar.gz 3.进行编译:./configure --prefix=/usr/local/rscript(--prefix的内容自定,这是R的安装目录) 注意:此过程中可能会出现以下错误: --with-readline=yes (default) and headers/libs are not available