美文网首页
Docker安装

Docker安装

作者: KN郑某某 | 来源:发表于2019-03-17 00:10 被阅读0次

    一、系统环境

    Centos7

    二、安装

    安装DockerCE版本,官方教程

    1、移除旧版本

    $ sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
    

    2、设置docker安装仓库

    $ sudo yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
    
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    

    3、安装

    • 安装默认版本
    $ sudo yum install docker-ce docker-ce-cli containerd.io
    
    • 安装特定版本

    如果需要安装特定版本,按下面的方式执行。 先查看现有的版本

    $ yum list docker-ce --showduplicates | sort -r
    

    显示如下

    docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
    docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
    ......

    安装18.09.8 版本

    $ sudo yum install docker-ce-18.09.8 docker-ce-cli-18.09.8 containerd.io
    

    4、启动

    $ sudo systemctl start docker
    

    设置开机启动

    $ sudo systemctl enable docker
    

    5、验证安装结果

    $ sudo 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/
    

    三、修改国内镜像源

    修改文件 /etc/docker/daemon.json,文件不存在就添加一个。添加配置

    {
      "registry-mirrors": ["https://hub-mirror.c.163.com","https://registry-1.docker.io"]
    }
    

    重启服务即可

    $ sudo systemctl restart docker
    

    四、卸载

    • 卸载
    $ sudo yum remove docker-ce docker-ce-cli containerd.io
    
    • 删除目录
    $ rm -rf /var/lib/docker
    

    删除 /var/lib/docker目录后,原先的镜像和容器都会被删除,请谨慎操作。如果只是为了更新,那么 /var/lib/docker 不需要删除。

    相关文章

      网友评论

          本文标题:Docker安装

          本文链接:https://www.haomeiwen.com/subject/lriemqtx.html