Skip to content

Instantly share code, notes, and snippets.

@blanklin030
Last active January 24, 2019 07:04
Show Gist options
  • Save blanklin030/f09b7e9ff671f65f88e0793c42f497b5 to your computer and use it in GitHub Desktop.
Save blanklin030/f09b7e9ff671f65f88e0793c42f497b5 to your computer and use it in GitHub Desktop.
在centos7上安装docker

1、通过yum安装

  • 1.1、通过 uname -r 命令查看你当前的内核版本
  • 1.2、通过yum安装docker服务
yum -y install docker
yum -y install docker-compose
  • 1.3、启动docker后台服务
service docker start
  • 1.4、测试运行 hello-world
docker run hello-world

2、使用脚本安装 Docker

  • 2.1、确保 yum 包更新到最新
sudo yum update
  • 2.2、执行 Docker 安装脚本
curl -fsSL https://get.docker.com/ | sh
  • 2.3、启动 Docker 进程
sudo service docker start
  • 2.4、验证 docker 是否安装成功并在容器中执行一个测试的镜像
sudo docker run hello-world

3、开启docker

service docker start //centos6
systemctl start docker //centos7以上版本

4、hello world容器内测试

docker run ubuntu:15.10 /bin/echo "Hello world"
  • 错误提示
/usr/bin/docker-current: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96/data?Expires=1526904899&Signature=K82XtPVTlbPAPukeQnfQQqYlGnN~aQK3lqmWZDxQobOH9u0SjoFntXG1SydPk97ESwsb--iy4kPC4LbhHSKeyuIuwO5bm6hCGlqts~Ci0Oc69faXs1Ra9DBAhA2w-AIIBrNeyYpdMlpalES1t25GyJSk0sbZJdh62jRnwlWRxoM_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.
  • 分析原因
    • 这是因为docker的服务器不在中国,无法连接到docker hub
  • 解决方法
    • 停止docker服务
    systemctl stop docker
    • 修改docker镜像源
    vim /etc/docker/daemon.json
    { 
      "registry-mirrors": ["https://registry.docker-cn.com"] 
    }
  • 错误提示
  /usr/bin/docker-current: Error response from daemon: error creating overlay mount to /var/lib/docker/overlay2/1360d2245f8c5f263dee19ccf248e6e3773e06eb5b7be255f0df10e8bef7d9b6/merged: invalid argument.
  • 分析原因
    • 用的overlay2文件系统,而系统默认只能识别overlay文件系统
  • 解决方法
systemctl stop docker      //停掉docker服务  
rm -rf /var/lib/docker     //注意会清掉docker images的镜像  
vi /etc/sysconfig/docker-storage       //将文件里的overlay2改成overlay即可  

image

5、安装docker-compose

//下载安装epel扩展源
sudo yum -y install epel-release
//安装python-pip
sudo yum install python-pip.noarch
//提示No package python-pip available.Error: Nothing to do 因为没有此rpm包,此包包含在epel源里面 
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum install python-pip
//对安装好的pip进行一次升级
sudo pip install --upgrade pip
//安装docker-compose
sudo pip install docker-compose
//安装失败则使用下面更新pip后再次安装
python -m pip install --upgrade pip

出现报错

Cannot uninstall 'requests'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall

错误的原因是requests 默认版本为2.6.0,而geoip2需要2.9以上版本才支持,但是无法正常卸载2.6.0版本。通过google查找后,发现是pip10对包的管理存在变化。

解决方法

//通过如下方式强制重新安装requests
pip install -I requests==2.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment