第1章 Linux-Centos7.2安装Docker

来源:互联网 发布:怎样注册一个域名 编辑:程序博客网 时间:2024/05/29 18:38



Docker简介

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)。几乎没有性能开销,可以很容易地在机器和数据中心中运行。最重要的是,他们不依赖于任何语言、框架包括系统。 
百度百科

前提

首先,你的Centos的系统一定要是64位的,不管版本是什么。并且内核版本至少是3.10以上。 
用以下命令去查看你的内核版本:

$ uname -r3.10.0-229.el7.x86_64
  • 1
  • 2
  • 1
  • 2

最后,建议你更新你的系统,因为最新内核可能会修复了旧版本的一些bug。

安装

yum安装

用具有sudo或者root权限的用户登录系统。

确保你的yum包已经更新

$ sudo yum update
  • 1
  • 1

添加yum仓库

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'[dockerrepo]name=Docker Repositorybaseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/enabled=1gpgcheck=1gpgkey=https://yum.dockerproject.org/gpgEOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

安装Docker包

$ sudo yum install docker-engine
  • 1
  • 1
  • 开启docker deamon
$ sudo service docker start
  • 1
  • 1

验证docker是否成功安装

$ sudo docker run hello-worldUnable to find image 'hello-world:latest' locally    latest: Pulling from hello-world    a8219747be10: Pull complete    91c95931e552: Already exists    hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.    Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d    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.            (Assuming it was not already locally available.)     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    For more examples and ideas, visit:     http://docs.docker.com/userguide/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

开机自启动

$ sudo chkconfig docker on
  • 1
  • 1

卸载

列出你安装过的包

$ yum list installed | grep dockeryum list installed | grep dockerdocker-engine.x86_64   1.7.1-1.el7 @/docker-engine-1.7.1-1.el7.x86_64.rpm
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

删除安装包

$ sudo yum -y remove docker-engine.x86_64
  • 1
  • 1

删除镜像/容器等

$ rm -rf /var/lib/docker

查看 docker version


镜像加速器配置

curl -sSL https://get.daocloud.io/daotools

/set_mirror.sh | sh -s http://8a4c4344.m.daocloud.io


阿里云加速
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -



centos系统阿里云 https://cr.console.aliyun.com/#/accelerator先登录阿里云 在访问 访问了点击docker hub镜像站点根据系统要求配置


c. 『CentOS/RedHat』注意事项
① 关闭 selinux 防火墙:
setenforce 0  #关闭selinux防火墙,临时关闭。永久关闭需改/etc/selinux/config文件,将SELINUX=enforcing改为SELINUX=disabled 并重启操作系统
② 关闭 firewalld 防火墙(操作系统是最下化安装的,这个为默认关闭)
systemctl stop firewalld.service   #关闭firewalld防火墙 」

原创粉丝点击