当前位置:首页 > 未命名 > 正文内容

Ubuntu安装docker

淙嶙7年前 (2018-06-29)未命名1322

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,

image.png

通过编辑或新增/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


相关文章

大数相减

大数相减

描述 两个长度超出常规整形变量上限的大数相减,请避免使用各语言内置大数处理库,如 Java.math.BigInteger 等。 输入 有 N 行测试数据,每一行有两个代表整数的字符串 a 和 b,...

idea 打开文件所在位置

idea 打开文件所在位置

工欲善其事,必先利其器。idea默认自带打开选中文件的资源管理器位置,右键文件,选择Show in Exlporer;如果希望将它显示在工具栏中,则需要完成一些设置: 1首先保证你的工具栏是...

最少交换次数

最少交换次数

描述 给出一个无序数列,每次只能交换相邻两个元素,求将原数列变成递增数列的最少交换次数。如:数列:2,3,1,交换3和1后变成:2,1,3;交换1和2之后变成:1,2,3。总共交换2次。...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。