centos 安装 docker

来源:互联网 发布:中国大数据规划图 编辑:程序博客网 时间:2024/06/05 12:14

centos 安装 docker

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

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

$ uname -r3.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-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldc04b14da8d14: Pull completeDigest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9Status: 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.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 bashShare images, automate workflows, and more with a free Docker Hub account:https://hub.docker.comFor 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 dockergroupadd:“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 dockerdocker-engine.x86_64                   1.12.3-1.el7.centos             @dockerrepodocker-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 1
原创粉丝点击