centos 安装 docker

centos 安装 docker

https://docs.docker.com/engine/installation/linux/centos/

前期准备:需要64位操作系统,3.10版本以上内核。

$ uname -r
3.10.0-229.el7.x86_64

安装docker 引擎

通过 yum 安装

  1. 通过 root 登录
  2. 系统更新

    $ sudo yum update
  3. 添加 repo 源

    $ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/7/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
  4. 安装 docker 包

    $ sudo yum install docker-engine
  5. 启用服务

    $ sudo systemctl enable docker.service
  6. 启动守护进程

    $ sudo systemctl start docker
  7. 测试是否安装成功

    $ sudo docker run --rm hello-world
    
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    c04b14da8d14: Pull complete
    Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
    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.
    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 Hub account:
    https://hub.docker.com
    
    For more examples and ideas, visit:
    https://docs.docker.com/engine/userguide/

    使用脚本安装

    1. 通过 root 登录
    2. 系统更新

      $ sudo yum update
    3. 运行docker 安装脚本

      $ curl -fsSL https://get.docker.com/ | sh
    4. 启用服务

      $ sudo systemctl enable docker.service
    5. 启动守护进程

      $ sudo systemctl start docker
    6. 测试是否安装成功

      $ sudo docker run --rm hello-world

    创建 docker 组

    为了启动 daemon 而不使用root

    1. root 权限
    2. 创建 docker 组

      $ sudo groupadd docker
      groupadd:“docker”组已存在
    3. 在 docker组添加用户

      此处先使用 useradd 、passwd 添加用户,设置密码
      $ sudo usermod -aG docker your_username
    4. 退出并且登录到your_username,如果在your_username下也建议退出再重新登录一次,这确保您的用户正在运行正确的权限。

    5. 验证运行docker已不再需要sudo命令
      $ docker run --rm hello-world

    开机启动 docker daemon

    $ sudo systemctl enable docker

    删除 docker (使用yum)

    1. 列出已安装的 docker 包

      $ yum list installed | grep docker
      docker-engine.x86_64                   1.12.3-1.el7.centos             @dockerrepo
      docker-engine-selinux.noarch           1.12.3-1.el7.centos             @dockerrepo
    2. 删除上面的包

      $ sudo yum -y remove docker-engine.x86_64
      $ sudo yum -y remove docker-engine-selinux.noarch
      *This command does not remove images, containers, volumes, or user-created configuration files on your host.*
    3. remove images, containers, volumes

      $ rm -rf /var/lib/docker
    4. Locate and delete any user-created configuration files.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值