• 欢迎访问金笔头博客,这是一个菜鸟(伪)程序员的自留地,欢迎访问我的github:点击进入

Docker笔记(2)-Ubuntu 16.04安装Docker

Docker eason 2318次浏览 0个评论 扫描二维码

准备工作

Docker支持如下Ubuntu系统:

  • Ubuntu Xenial 16.04 (LTS)
  • Ubuntu Wily 15.10
  • Ubuntu Trusty 14.04 (LTS)
  • Ubuntu Precise 12.04 (LTS)

其对系统有两个非常重要的要求:

  1. 仅支持64位Linux安装
  2. Linux系统内核版本不能低于3.10,否则Docker运行可能会丢失部分功能

我们可以执行如下命令查看本机内核版本

$ uname -r
4.4.0-57-generic

更新你的APT 源

更新包信息,确保APT 以https方式工作,并且CA certificates已经安装

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates

添加新的GPG密钥

$ sudo apt-key adv \
--keyserver hkp://ha.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Executing: /tmp/tmp.YvrVIpDeEW/gpg.1.sh --keyserver
hkp://ha.pool.sks-keyservers.net:80
--recv-keys
58118E89F3A912897C070ADBF76221572C52609D
gpg: 下载密钥‘2C52609D’,从 hkp 服务器 ha.pool.sks-keyservers.net
gpg: 密钥 2C52609D:公钥“Docker Release Tool (releasedocker) <docker@docker.com>”已导入
gpg: 合计被处理的数量:1
gpg:               已导入:1  (RSA: 1)

添加Docker的源

根据下表选择对应的源

Ubuntu version Repository
Precise 12.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-precise main
Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main
Wily 15.10 deb https://apt.dockerproject.org/repo ubuntu-wily main
Xenial 16.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-xenial main

由于本机为ubuntu16.04,所以执行如下命令添加Docker源

$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list

更新APT 包索引

$ sudo apt-get update

验证APT 是否能从正确的源拉取Docker信息

下列命令将会返回你可以安装的Docker版本信息,当前已安装版本前面将会以***标识,由下列输出信息可知当前未安装任何版本的Docker

$ apt-cache policy docker-engine
docker-engine:
  已安装:(无)
  候选: 1.12.5-0~ubuntu-xenial
  版本列表:
     1.12.5-0~ubuntu-xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.4-0~ubuntu-xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.3-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

一些其他包的安装

安装linux-image-extra-*内核包,这将允许你使用aufs文件系统

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

开始安装Docker

前面的步骤都完成以后,准备工作都已经做好了,现在开始正式安装。对于生产环境来说,官方文档推荐安装特定版本的Docker,这样的可以避免Docker意外更新,毕竟在生产环境更新Docker还是有风险的。本文就记录特定版本Docker的安装过程。 1.列出所有可用的docker-engine版本

$ apt-cache madison docker-engine
docker-engine | 1.12.5-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.4-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.3-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.2-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.1-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.0-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.2-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.1-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.0-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

输出信息每一行的第二个字段代表可用的Docker版本,这里我安装最新的1.12.5-0~ubuntu-xenial

$ sudo apt-get update
$ sudo apt-get install docker-engine=1.12.5-0~ubuntu-xenial

2.检验Docker是否安装成功 执行docker命令,输出如下信息说明安装成功

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

3.查看Docker信息 使用docker info命令查看docker信息

$ sudo docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.05.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 3
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9048e5e50717ea4497b757314bad98ea3763c145
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.10.0-28-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 10.33GiB
Name: eason-virtual-machine
ID: VKV5:ML4R:GZGB:LHJH:WRLQ:MYBL:UMT5:ABRD:QBZF:MYIS:TZTV:7NML
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

4.查看当前系统中所有容器

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
4726a51540bd        hello-world         "/hello"            12 minutes ago      Exited (0) 12 minutes ago                       serene_noyce

你应该会看到hello-world容器的所有信息,由状态字段我们可以知道该容器已经于12分钟之前退出了,去掉-a参数我们再次执行

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

发现啥都没有,这是因为docker ps命令只会显示当前正在运行中的容器信息。

设置Docker开机自启动

Ubuntu在15.04及以后版本中使用systemd来作为它的引导和服务管理工具,在14.10及以前版本中是使用upstart,本机为16.04,所以使用如下命令

$ sudo systemctl enable docker

金笔头博客, 版权所有丨如未注明 , 均为原创, 转载请注明Docker笔记(2)-Ubuntu 16.04安装Docker
喜欢 (1)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址