Ubuntu安装docker
1.查看ubuntu版本,官方指定的版本才能安装。https://docs.docker.com/install/linux/docker-ce/ubuntu/
To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:
Bionic 18.04 (LTS)
Artful 17.10
Xenial 16.04 (LTS)
Trusty 14.04 (LTS)
Docker CE is supported on Ubuntu on x86_64, armhf, s390x (IBM Z), and ppc64le (IBM Power) architectures.
我的ubantu版本:
sudo lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.4 LTS Release: 16.04 Codename: xenial uname -a Linux ubuntu 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2.删除已安装的旧版本
sudo apt-get remove docker docker-engine docker.io
3.支持的存储驱动 ,ubuntu 现在支持的存储驱动有overlay2和aufs两种。如果ubuntu的Linux内核版本是4以上,官方推荐使用overlay2; 如果版本是3的,推荐使用aufs。在ubuntu版本4以上默认有overlay2的,不需要安装。
cat /proc/version Linux version 4.13.0-39-generic (buildd@lcy01-amd64-024) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)) #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018
4.安装依赖
安装方式有多种,这里只采用apt-get install
a. 更新apt索引
sudo apt-get update
b. 允许apt使用https的方式安装软件
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
c. 安装docker的官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88
d. 安装stable
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
5 安装docker-ce
a 更新apt索引
sudo apt-get update
b开始安装docker-ce,需要确认的选中 Y.
sudo apt-get install docker-ce 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: libappindicator1 libindicator7 libllvm4.0 linux-headers-4.10.0-40 linux-headers-4.10.0-40-generic linux-headers-4.8.0-36 linux-headers-4.8.0-36-generic linux-image-4.10.0-40-generic linux-image-4.8.0-36-generic linux-image-extra-4.10.0-40-generic linux-image-extra-4.8.0-36-generic snap-confine 使用'sudo apt autoremove'来卸载它(它们)。 将会同时安装下列软件: aufs-tools cgroupfs-mount pigz 下列【新】软件包将被安装: aufs-tools cgroupfs-mount docker-ce pigz 升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 121 个软件包未被升级。 需要下载 34.2 MB 的归档。 解压缩后会消耗 182 MB 的额外空间。 您希望继续执行吗? [Y/n]
c 如果想安装指定版本的docker,可以执行下面的命令
apt-cache madison docker-ce docker-ce | 18.03.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages sudo apt-get install docker-ce=<VERSION> #VERSION 替换成需要的版本如:18.03.1~ce-0~ubuntu
d 查看是否安装成功 client 和server都存在,说明安装成功。
sudo docker version Client: Version: 18.03.1-ce API version: 1.37 Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:17:20 2018 OS/Arch: linux/amd64 Experimental: false Orchestrator: swarm Server: Engine: Version: 18.03.1-ce API version: 1.37 (minimum version 1.12) Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:15:30 2018 OS/Arch: linux/amd64 Experimental: false
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/engine/userguide/
6 镜像加速器
用于解决由于国内网络访问问题,导致的拉取docker镜像缓慢的问题,当前我所知道的有阿里的镜像加速器和网易的镜像加速器,这里选用阿里的镜像加速器。可以去阿里云官网找首页的产品->弹性计算->容器镜像服务。或者访问https://cr.console.aliyun.com/#/accelerator,
通过编辑或新增/etc/docker/daemon.json这个文件
sudo vi /etc/docker/daemon.json { "registry-mirrors":["https://z46ilxj9.mirror.aliyuncs.com"] } sudo systemctl daemon-reload sudo systemctl restart docker