docker安装(CentOS 7)

/ 技术分享 / 没有评论 / 5311浏览

一、yum安装docker(CentOS 7)

  1. 移除旧的版本:

     $ 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. 添加软件源信息:

     $ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
  4. 更新 yum 缓存:

     $ sudo yum makecache fast
    
  5. 安装 Docker-ce:

     $ sudo yum -y install docker-ce
    
  6. 启动 Docker 后台服务

     $ sudo systemctl start docker
    
  7. 测试运行 hello-world

         [root@localhost docker]# docker run hello-world
    
             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/get-started/
    

二、使用脚本安装 Docker

  1. 使用 sudo 或 root 权限登录 Centos。

  2. 确保 yum 包更新到最新。

     $ sudo yum update
    
  3. 执行 Docker 安装脚本。

     $ curl -fsSL https://get.docker.com -o get-docker.sh
     $ sudo sh get-docker.sh
    
    • 执行这个脚本会添加 docker.repo 源并安装 Docker。
  4. 启动 Docker 进程

     $ sudo systemctl start docker
    
  5. 验证 docker 是否安装成功并在容器中执行一个测试的镜像。

     $ sudo docker run hello-world
    

三、镜像加速

四、删除 Docker CE