zoukankan      html  css  js  c++  java
  • centos7 下安装Docker CE

    前提条件

    操作系统要求

    • 要保证centos-extrasrepository开启(enabled)。默认处于开启状态。
    • 推荐使用overlay2存储驱动

    卸载老版本

    $ 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
    

    安装 Docker CE

    推荐使用国内的阿里Docker镜像源进行安装,安装国外官方源需要翻墙

    方法1: 使用repository进行安装

    1) 安装依赖库

    $ sudo yum install -y yum-utils 
      device-mapper-persistent-data 
      lvm2
    

    2) 安装稳定版repository

    方式1> 使用国内阿里云Docker镜像源[国内推荐]

    sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    

    方式2> 使用国外官方镜像源[国内不推荐]

    $ sudo yum-config-manager 
        --add-repo 
        https://download.docker.com/linux/centos/docker-ce.repo
    

    3) 安装Docker CE

    1. 安装最新版
    $ sudo yum install docker-ce
    
    2. 安装指定版本
    # 查看版本号
    $ yum list docker-ce --showduplicates | sort -r
    # 安装指定版本,
    $ sudo yum install docker-ce-<VERSION STRING>
    形如:
    $ sudo yum install docker-ce-17.06.2.ce
    

    4) 启动Docker

    $ sudo systemctl start docker
    

    查看docker运行状态

    $ ps aux | grep docker
    root      3663  0.9  4.9 499232 24668 ?        Ssl  15:58   0:00 /usr/bin/dockerd
    root      3666  0.0  1.1 263984  5496 ?        Ssl  15:58   0:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
    bob       3770  0.0  0.1 112704   972 pts/0    R+   15:59   0:00 grep --color=auto docker
    

    5) 验证docker是否安装正确

    1. 以root身份运行hello-world
    $ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete 
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    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.
        (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/
    
    1. 以非root用户权限运行hello-world
    # 1. 首先要确保docker服务已经启动
    $ systemctl status docker
    # 2. 创建名为docker的组
    $ sudo groupadd docker
    # 3. 将当前用户加入到docker组中
    $ sudo usermod -aG docker $USER
    # 4. 注销,如果远程登录先断开连接在重新连接,使得usermod修改生效,这一步非常重要
    # 5. 验证
    $ docker run hello-world
    

    usermod修改后不会立即生效

    # 查看当前用户所属组
    $ groups 
    bob sudo
    # 查看指定用户所属组
    $ groups bob
    bob : bob sudo
    # 查看当前用户信息
    $ id
    uid=1000(bob) gid=1000(bob) groups=1000(bob),27(sudo)
    $ sudo usermod -aG docker bob
    $ groups
    bob sudo
    $ id
    uid=1000(bob) gid=1000(bob) groups=1000(bob),27(sudo)
    # 可以发现usermod修改后并未立即生效
    如果是远程登录,可以先断开连接再重新连接,或是使用su进行切换命令
    $ su - bob
    Password: 
    $ groups
    bob sudo docker
    $ id
    uid=1000(bob) gid=1000(bob) groups=1000(bob),27(sudo),999(docker)
    # 重新登录发现修改生效
    

    方法2: rpm包安装

    rpm包下载地址

    方法3: 使用脚本一键安装 [推荐]

    方式1> 使用阿里Docker镜像源安装脚本[国内推荐]

    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    

    方式2> 使用官方安装脚本

    $ curl -fsSL https://get.docker.com -o get-docker.sh
    $ sudo sh get-docker.sh
    

    开机启动

    # 设置开机启动
    $ sudo systemctl enable docker
    # 关闭开机启动
    $ sudo systemctl disable docker
    

    卸载docker

    $ sudo systemctl stop docker
    # 卸载最新版docker
    $ sudo yum remove docker-ce
    # 卸载非最新版docker
    # 获取docker版本号
    $ rpm -qa | grep docker
    # 卸载指定版本
    $ sudo yum remove docker-ce-17.06.2.ce
    # 删除所有的images, containers, and volumes数据
    $ sudo rm  -rf /var/lib/docker/
    

    参考:

  • 相关阅读:
    JAVA数据库连接池
    数据库连接池总结 Proxool
    Linux下挂载ISO文件
    Runtime.getRuntime().addShutdownHook()的使用
    tomcat original passports setting
    JDBC之通过DatabaseMetaData对象了解数据库的信息
    linux下mysql远程登陆
    教您如何安全的应用 MySQL
    Eclipse中cvs的使用介绍
    WM_COPYDATA
  • 原文地址:https://www.cnblogs.com/hupeng1234/p/9773781.html
Copyright © 2011-2022 走看看