前提条件

操作系统

docker-ce支持的ubuntu版本:

  • Bionic 18.04 (LTS)
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

卸载旧版本docker[可选]

$ sudo apt-get remove docker docker-engine docker.io --purge

支持的存储驱动程序

对于ubuntu16.04及以上版本,其linux内核中包含了对于OverlayFS的支持。Docker CE默认使用overlay2存储引擎,如果想要使用aufs,可参考aufs

安装 Docker CE

方法1: 使用repository进行安装

Step1. 更新源,安装相应的依赖包

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

Step2 安装Docker镜像

方式1> 安装国内阿里Docker CE镜像[国内推荐]

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

方式2> 安装docker的官方 GPG key[国内不推荐,需要翻墙]:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

可能存在的问题:
如果等了很长时间也下载不了,说明被墙了,需要通过代理下载,例如使用本地的shawsocks代理

$ export https_proxy=socks5://127.0.0.1:1080
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

安装完成后,最好使用指纹9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88对key进行验证

$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22

Step3. 安装稳定版的repository

方式1> 阿里repository[国内推荐]

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

方式2> 官方repository[国内不推荐]

$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

4. 安装Docker CE

方式1) 安装最新版Docker CE
$ sudo apt-get update
$ sudo apt-get install docker-ce

如果使用国外官方镜像,可能存在以下问题:
update更新时间过长,一直卡住不动,形如:

$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu xenial-security InRelease
0% [Working]

或是

  Could not resolve host: download.docker.com
Reading package lists... Done
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/xenial/InRelease Could not resolve host: download.docker.com

或是

Err:5 https://download.docker.com/linux/ubuntu xenial InRelease
Operation timed out after 0 milliseconds with 0 out of 0 bytes received
Reading package lists... Done
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/xenial/InRelease Operation timed out after 0 milliseconds with 0 out of 0 bytes received
方式2) 安装指定版本Docker CE
# 获取可用版本
$ apt-cache madison docker-ce
# 安装指定版本
$ sudo apt-get install docker-ce=<VERSION>
例如:
$ sudo apt-get install docker-ce=17.06.2~ce-0~ubuntu

5. 验证Docker CE是否成功安装

方式1) 以root身份运行hello-world

$ sudo docker run hello-world

方式2) 以普通用户身份运行hello-world

# 0. 首先要确保docker服务已经启动
$ systemctl status docker # 1. 使用root身份创建用户并设置密码,给用户添加及sudo权限[如果有普通用户可跳过,这里是为了演示需要]
# 创建新用户bob
# useradd -m -d /home/bob -s /bin/bash bob
# passwd bob
# tail -n 1 /etc/passwd
bob:x:1000:1000::/home/bob:/bin/bash # 该bob添加sudo权限
# usermod -aG sudo bob # 下面使用bob登录
# su - bob # 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: deb包安装

deb包下载地址

方法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 CE 彻底卸载

# Step1: 关闭服务
$ sudo service docker stop # Step2: 查看安装的软件包
$ dpkg -l | grep -i docker # Step3: 卸载
$ sudo apt-get purge -y docker-engine docker docker.io docker-ce
$ sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce # Step4: 删除相关数据和配置文件
$ sudo ls /var/lib/docker/
aufs containers image network plugins swarm tmp trust volumes
$ sudo rm -rf /var/lib/docker
$ sudo rm /etc/apparmor.d/docker
$ sudo groupdel docker
$ sudo rm -rf /var/run/docker /var/run/docker.sock # Step5: 删除interface docker0
$ sudo ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:03:99:8a:e8
$ sudo ip link del docker0

参考:

  • https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • https://docs.docker.com/install/linux/linux-postinstall/
  • https://askubuntu.com/questions/935569/how-to-completely-uninstall-docker
  • https://yq.aliyun.com/articles/110806?spm=a2c4e.11153940.blogcont7695.8.62c41987TIV4bF

ubuntu16.04下docker安装和简单使用(转)的更多相关文章

  1. ubuntu16.04下docker安装和简单使用

    前提条件 操作系统 docker-ce支持的ubuntu版本: Bionic 18.04 (LTS) Xenial 16.04 (LTS) Trusty 14.04 (LTS) 卸载旧版本docker ...

  2. Ubuntu16.04下编译安装OpenCV3.4.0(C++ & python)

    Ubuntu16.04下编译安装OpenCV3.4.0(C++ & python) 前提是已经安装了python2,python3 1)安装各种依赖库 sudo apt-get update ...

  3. Ubuntu16.04 下如何安装搜狗拼音输入法【亲测有效】

    Ubuntu16.04 下如何安装搜狗拼音输入法[亲测有效]   一.添加fcitx键盘输入法系统[系统默认是iBus] 1.将下载源添加至系统源: sudo add-apt-repository p ...

  4. Ubuntu16.04下编译安装及运行单目ORBSLAM2

    官网有源代码和配置教程,地址是 https://github.com/raulmur/ORB_SLAM2 1 安装必要工具 首先,有两个工具是需要提前安装的.即cmake和Git. sudo apt- ...

  5. Ubuntu-16.04下Docker通过阿里云镜像安装(apt-get)

    由于通过官方路径安装docker时总是连接不上,所以从网上找了半天,通过阿里云镜像安装docker,我的Linux是ubuntu-16.04 一.配置源里的阿里云镜像仓库 sudo vim /etc/ ...

  6. Ubuntu16.04 下docker部署web项目

    概念性的请戳 第一步:更新apt-get update 第二步:安装环境 apt-get install \ apt-transport-https \ ca-certificates \ curl ...

  7. Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)

    Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...

  8. ubuntu16.04下编译安装vim8.1

    之前写过一篇centos7下编译安装vim8.0的教程,ubuntu16.04相比centos7下安装过程不同在于依赖包名字的不同,其余都是一样.下面给出ubuntu16.04编译安装vim8.0需要 ...

  9. ubuntu16.04下g++安装及使用

    1)首先在虚拟机中安装Ubuntu16.04,网络模式设置为NAT模式,安装完成后在虚拟机中测试是否能够上网. 2)进入Ubuntu,按Ctrl+alt+T,调出终端,输入sudo su,输入密码切换 ...

随机推荐

  1. Linux添加用户到sudoers组

    切换用户至rootvim /etc/sudoers 找到root    ALL=(ALL)       ALL,在下方新增 stack  ALL=(ALL)       NOPASSWD: ALL w ...

  2. SQL Server阻塞blocking案例分析

    今天在性能测试过程中发现大量阻塞报警,检查whoisactive(https://github.com/amachanic/sp_whoisactive/)数据发现,阻塞blocking头部sessi ...

  3. jQuery easyui datagrid 的数据加载

        其实easyuidatagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数据:另一种是加载js对象,也就是使用loadDate方法,这种方法用于加载本地js数据(非ur ...

  4. C#调用windows API实现 smallpdf客户端程序进行批量压缩

    一.背景 Smallpdf 网站针对PDF文件提供了非常齐全的功能:PDF 与 Word.PPT.Excel.JPG 的相互转化.PDF 的压缩.编辑.合并.分割.解密.加密等功能,用户无需注册即可免 ...

  5. laravel Route::resource() 资源路由

    格式: Route::resource('/order', 'OrderController', ['as' => 'admin']); 框架自动创建路由及其对应控制器中的方法: 请求方式 路由 ...

  6. 使用MingGW-w64 Build Script 3.6.7搭建ffmpeg编译环境

    在Linux下编译的Windows版本ffmpeg没有其他的依赖库 使用的是centos 1.脚本下载 wget http://zeranoe.com/scripts/mingw_w64_build/ ...

  7. Python深度学习读书笔记-4.神经网络入门

    神经网络剖析   训练神经网络主要围绕以下四个方面: 层,多个层组合成网络(或模型) 输入数据和相应的目标 损失函数,即用于学习的反馈信号 优化器,决定学习过程如何进行   如图 3-1 所示:多个层 ...

  8. tf多值离散embedding方法

    https://www.jianshu.com/p/4a7525c018b2 注意:一个域下的多值情况,这里最终输出是直接给出来每个域的(多值)的embedding值,多个值的也只输出一个embedd ...

  9. saml2协议sp-initial登录过程

    登录过程如下所示: 一次完整的saml认证过程,包括一次samlrequest和samlresponse, 首先用户如果想访问一个sp,sp会先检验用户是否登录,如果用户已经登录,即可以正常访问sp的 ...

  10. vue-loader分析

    分析一下Vue2.0中的vue-loader是如何处理.vue单文件组件的: 1.vueLoaderplugin 作用是 找到.vue,.vue.html的rules然后在他们的rule里添加 pit ...