在Ubuntu16.04中安装Docker Ce
卸载旧版本
#如果之前安装过docker.io,没有跳过 eric@userver:~$ sudo apt-get remove docker docker-engine docker.io
安装AUFS 内核驱动模块
#aufs是docker存储驱动推荐的内核模块,如果系统没有安装,执行下面脚本 eric@userver:~$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
安装镜像源
#添加使用https传输软件包及CA证书,保证官方源不被篡改 eric@userver:~$ sudo apt update eric@userver:~$ sudo apt install apt-transport-https ca-certificates curl software-properties-common #国内源,推荐 eric@userver:~$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - #官方源,速度较慢,有可能下载失败 eric@userver:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加软件源
#向soruce.list中添加Docker软件源 eric@userver:~$ sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装Docker CE
#使用脚本自动安装(推荐) eric@userver:~$ curl -fsSL get.docker.com -o get-docker.sh eric@userver:~$ sudo sh get-docker.sh --mirror Aliyun #apt 安装docker ce eric@userver:~$ sudo apt-get update eric@userver:~$ sudo apt-get install docker-ce
启动Docker CE
eric@userver:~$ sudo systemctl enable docker eric@userver:~$ sudo systemctl start docker #ubuntu14.04使用下面命令 eric@userver:~$ sudo service docker start
将当前用户加入docker组
#默认情况,docker命令会使用unix socket 与docker引擎通讯,只有root和docker的用户才能访问 #建立docker组:默认安装docker时候已经生成 eric@userver:~$ sudo groupadd docker #将当前用户加入 docker 组 sudo usermod -aG docker $USER #退出终端,重新登录使生效
测试
eric@userver:~$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:445b2fe9afea8b4aa0b2f27fe49dd6ad130dfe7a8fd0832be5de99625dad47cd 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ #成功查看容器 出现hello-world eric@userver:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 4 weeks ago 1.85kB
使用镜像加速
由于国内网络问题,拉取dokcer镜像十分缓慢,建议配置国内镜像加速。
我使用的是阿里云加速(https://yq.aliyun.com/articles/29941)