基于 Ubuntu 16.04 LTS 安装 Docker (使用公网脚本 或 apt-get 安装)


       


       

看这里:

        戳此链接 通往 关于 Docker 所有的学习文章


1、安装前:Docker 对于 版本 及 内核 要求:

1.1、版本:

①、ubuntu 12.04 LTS (最低版本)
②、ubuntu 14.04 LTS
③、ubuntu 16.04 LTS (稳定性上推荐使用这个或下面的 ubuntu 18.04 )
④、ubuntu 18.04 LTS

LTS : Ubuntu发行版本中,LTS 意味着 更稳定的功能 及 更长时间的升级支持(目前为5年)
 
生产环境中当然推荐使用 LTS 版本
 
Ubuntu 如何查看 是不是 LTS版本?
①、cat /etc/issue
②、或者在 login shell 时(输入用户名+密码 登录系统之前),也有系统弹出的消息可以查看!
③、使用 lsb_release -a 命令即可!

1.2、kernal :

Docker 要求 你的 Ubuntu kernel 版本得 高于 3.10 !


root@zhengzelin:~# uname -r
4.4.0-93-generic

root@zhengzelin:~# cat /proc/version
Linux version 4.4.0-93-generic (buildd@lgw01-03) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017

内核要求满足,开始安装 Docker !

扫描二维码关注公众号,回复: 10693250 查看本文章

1.3、Docker 使用 aufs存储 :

如果使用 Ubuntu 16.04 LTS 版本,为了让 Docker 使用 aufs 存储,推荐安装两个软件包:

sudo apt-get update
sudo apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual

       


       

2、开始安装 Docker:

       

2.1、使用 apt-get :

①、安装 使系统支持 https 协议的源 的软件包:
root@zhengzelin:~\# apt-get update
root@zhengzelin:~\# apt-get install apt-transport-https ca-certificates curl software-properties-common 
②、添加 源 的 gpg密钥:
root@zhengzelin:~\# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
OK

# 非管理员,使用 sudo apt-key add -
③、查看 GPG 的公钥:
# 是查看的 指纹为 : “9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88” 的 GPG 的公钥:

使用命令:
root@zhengzelin:~# apt-key fingerprint 0EBFCD88


输出结果:
root@zhengzelin:~# 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) <[email protected]>
sub   4096R/F273FCD8 2017-02-22
④、使用 lsb_release 获取当前 操作系统 的代号:
root@zhengzelin:~# lsb_release -cs
xenial

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

lsb_release 命令介绍:

root@zhengzelin:~# type lsb_release 
lsb_release is hashed (/usr/bin/lsb_release) —— 外部命令

root @ zhengzelin:〜#lsb_release --help
用法:lsb_release [选项]
选项:
   -h,--help显示此帮助消息并退出
   -v,--version显示该系统支持的LSB模块
   -i,-id显示分发服务器ID
   -d,--description显示此发行版的描述
   -r,--release显示此发行版的发行版号
   "-c,--codename显示此发行版的代码名称"
   -a,--all显示以上所有信息
   "-s,--short以短格式显示请求的信息"

不加 -s 选项输出为这样:
root@zhengzelin:~# lsb_release -c
Codename:	xenial

# 一般情况下,Ubuntu 16.04 版本代码名称为 xenial ;18.04 为 bionic
⑤、添加 Docker 官方稳定版 的源:
root@zhengzelin:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
root@zhengzelin:~# echo $?
0

注意上面的 arch=amd64 和 xenial ; 你可以使用上面的 lsb_release 来查看你自己的服务器是什么类型的,然后替换为你自己服务器的参数即可!
⑥、再次 更新 apt 包:
root@zhengzelin:~# apt-get update
⑦、开始安装 Docker 并 查看版本:
注意: 软件包的名称为 docker-ce (ce 为社区版本!)

root@zhengzelin:~# apt-get -y install docker-ce

安装成功查看版本:
root@zhengzelin:~# docker -v
Docker version 19.03.8, build afacb8b7f0
⑧、或者可以安装 软件源中 docker 的指定版本~
root@zhengzelin:~# apt-cache madison docker-ce 
 ......
 docker-ce | 5:19.03.8~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 5:19.03.7~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 ......
 docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

在这里插入图片描述
有很多版本,你可以选择合适的进行安装:

假如你选择的是  docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

格式:sudo apt-get install docker-ce=17.03.0~ce-0~ubuntu  即可!
⑨、查看 Docker 运行状态,并查看是否为开机自启动:

在 Ubuntu 中 ,使用 sysv-rc-conf 命令来设置开机自启动!用法与 chkconfig 基本一致!

1、安装 sysv-rc-conf :
sudo apt-get -y isntall sysv-rc-conf

2、查看 开机自启动列表:
sysv-rc-conf --list

3、查看是否有docker:
root@zhengzelin:~# sysv-rc-conf --list docker
docker       0:off	1:off	2:on	3:on	4:on	5:on	6:off

基本上 在 2-5 运行级别 为 on 就可以!

简单回顾一下 运行级别:
0:关机
1:单用户模式
2:无网络支持的多用户模式
3:字符界面(有网络支持的多用户模式 最常用!)
4:保留未使用
5:图形界面(有网络支持的多用户模式,不常用,占用系统资源大!)
6: 重启

runlevel  # 查看当前所在运行级别

4、如果没有的话: 
sudo sysv-re-conf docker on

       


       

2.2、使用 脚本:

       
虽然是换一种方式安装 Docker ,但是 上面对于 Ubuntu版本 和 kernel 的要求还是一样的!

安装方法:


1、使用 wget 命令:
wget -qO- https://get.docker.com/ | sh

2、使用 curl 命令:
curl -sSL https://get.docker.com/ | sh

# 非root用户记得使用 sudo 命令

3、使用 阿里 的脚本安装:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

安装完成信息提示:

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 01:24:30 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
# 如果您想以非root用户身份使用Docker,现在应该考虑将您的用户添加到“ docker”组中,如下所示:

sudo usermod -aG docker your-username


Remember that you will have to log out and back in for this to take effect!
# 请记住,您必须先注销然后重新登录才能生效;


WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

记得使用其他用户使用docker,要将其加入 docker 组 !还得注销重新登陆才生效!

root@zhengzelin:~# docker --version 
Docker version 19.03.8, build afacb8b7f0

启动 Docker 并且运行 hello-world 镜像!

root@zhengzelin:~# service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-04-11 13:39:36 CST; 55s ago

root@zhengzelin:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        15 months ago       1.84kB
root@zhengzelin:~# docker run hello-world

Hello from Docker!
.......

别忘了 开机自启动,一般 docker 安装成功都为 开机自启动,使用 sysv-rc-conf ,具体用法 上面第⑨步有!

发布了101 篇原创文章 · 获赞 74 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ljlfather/article/details/105444120