1.检查系统内核版本,至少高于3.10.
root@ubuntu02:~# uname -r
4.4.0-31-generic

root@ubuntu02:~# cat /proc/version
Linux version 4.4.0-31-generic (buildd@lgw01-43) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016

2.检查ubuntu具体版本.
root@ubuntu02:~# cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

3.安装额外依赖包,是为了docker可以使用aufs存储功能,实践上系统已经默认安装了。
root@ubuntu02:~# apt-get install -y linux-image-extra-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-image-extra-4.4.0-31-generic is already the newest version.
linux-image-extra-4.4.0-31-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@ubuntu02:~#

4.安装https协议源,实践上系统已经默认安装了.
root@ubuntu02:~# apt-get install -y apt-transport-https
Reading package lists... Done
Building dependency tree
Reading state information... Done
apt-transport-https is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

5.查看系统当前代号,其实这个无关紧要。
root@ubuntu02:~# lsb_release -c
Codename: trusty
root@ubuntu02:~#

6.添加docker 官方yum源。
root@ubuntu02:/etc/apt/sources.list.d# vi docker.listbr/>root@ubuntu02:/etc/apt/sources.list.d#
root@ubuntu02:/etc/apt/sources.list.d# cat docker.list
deb https://apt.dockerproject.org/repo ubuntu-trusty main

7.更新系统yum源配置,更新 apt 软件包索引
root@ubuntu02:~# apt-get update
Get:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
Ign http://us.archive.ubuntu.com trusty InRelease
Get:2 http://us.archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Ign https://apt.dockerproject.org ubuntu-trusty InRelease
Get:3 http://security.ubuntu.com trusty-security/main Sources [147 kB]
Get:4 https://apt.dockerproject.org ubuntu-trusty/main amd64 Packages
Get:5 http://us.archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Get:6 https://apt.dockerproject.org ubuntu-trusty/main i386 Packages
Get:7 https://apt.dockerproject.org ubuntu-trusty/main Translation-en_US
Hit http://us.archive.ubuntu.com trusty Release.gpg
Get:8 http://us.archive.ubuntu.com trusty-updates/main Sources [409 kB]
Get:9 http://security.ubuntu.com trusty-security/restricted Sources [4,931 B]
Get:10 http://security.ubuntu.com trusty-security/universe Sources [67.2 kB]
Ign https://apt.dockerproject.org ubuntu-trusty/main Translation-en_US
Get:11 http://security.ubuntu.com trusty-security/multiverse Sources [3,182 B]
Ign https://apt.dockerproject.org ubuntu-trusty/main Translation-en
Get:12 http://us.archive.ubuntu.com trusty-updates/restricted Sources [6,322 B]
Get:13 http://security.ubuntu.com trusty-security/main amd64 Packages [698 kB]
Get:14 http://us.archive.ubuntu.com trusty-updates/universe Sources [195 kB]
Get:15 http://us.archive.ubuntu.com trusty-updates/multiverse Sources [7,781 B]
Get:16 http://us.archive.ubuntu.com trusty-updates/main amd64 Packages [1,045 kB]
Get:17 http://us.archive.ubuntu.com trusty-updates/restricted amd64 Packages [17.2 kB]
Get:18 http://security.ubuntu.com trusty-security/restricted amd64 Packages [14.1 kB]
Get:19 http://us.archive.ubuntu.com trusty-updates/universe amd64 Packages [437 kB]
Get:20 http://security.ubuntu.com trusty-security/universe amd64 Packages [199 kB]
Get:21 http://security.ubuntu.com trusty-security/multiverse amd64 Packages [4,800 B]
Get:22 http://us.archive.ubuntu.com trusty-updates/multiverse amd64 Packages [14.9 kB]
Get:23 http://security.ubuntu.com trusty-security/main i386 Packages [641 kB]
Get:24 http://us.archive.ubuntu.com trusty-updates/main i386 Packages [985 kB]
Get:25 http://us.archive.ubuntu.com trusty-updates/restricted i386 Packages [17.0 kB]
Get:26 http://us.archive.ubuntu.com trusty-updates/universe i386 Packages [435 kB]
Get:27 http://security.ubuntu.com trusty-security/restricted i386 Packages [13.9 kB]
Get:28 http://security.ubuntu.com trusty-security/universe i386 Packages [195 kB]
Get:29 http://security.ubuntu.com trusty-security/multiverse i386 Packages [4,958 B]
Get:30 http://us.archive.ubuntu.com trusty-updates/multiverse i386 Packages [15.3 kB]
Get:31 http://us.archive.ubuntu.com trusty-updates/main Translation-en [516 kB]
Get:32 http://security.ubuntu.com trusty-security/main Translation-en [375 kB]
Get:33 http://security.ubuntu.com trusty-security/multiverse Translation-en [2,564 B]
Get:34 http://us.archive.ubuntu.com trusty-updates/multiverse Translation-en [7,760 B]
Get:35 http://security.ubuntu.com trusty-security/restricted Translation-en [3,542 B]
Get:36 http://us.archive.ubuntu.com trusty-updates/restricted Translation-en [4,031 B]
Get:37 http://us.archive.ubuntu.com trusty-updates/universe Translation-en [236 kB]
Get:38 http://security.ubuntu.com trusty-security/universe Translation-en [113 kB]
Get:39 http://us.archive.ubuntu.com trusty-backports/main Sources [9,709 B]
Get:40 http://us.archive.ubuntu.com trusty-backports/restricted Sources [28 B]
Get:41 http://us.archive.ubuntu.com trusty-backports/universe Sources [35.4 kB]
Get:42 http://us.archive.ubuntu.com trusty-backports/multiverse Sources [1,896 B]
Get:43 http://us.archive.ubuntu.com trusty-backports/main amd64 Packages [13.3 kB]
Get:44 http://us.archive.ubuntu.com trusty-backports/restricted amd64 Packages [28 B]
Get:45 http://us.archive.ubuntu.com trusty-backports/universe amd64 Packages [43.1 kB]
Get:46 http://us.archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1,567 B]
Get:47 http://us.archive.ubuntu.com trusty-backports/main i386 Packages [13.3 kB]
Get:48 http://us.archive.ubuntu.com trusty-backports/restricted i386 Packages [28 B]
Get:49 http://us.archive.ubuntu.com trusty-backports/universe i386 Packages [43.2 kB]
Get:50 http://us.archive.ubuntu.com trusty-backports/multiverse i386 Packages [1,551 B]
Get:51 http://us.archive.ubuntu.com trusty-backports/main Translation-en [7,503 B]
Get:52 http://us.archive.ubuntu.com trusty-backports/multiverse Translation-en [1,215 B]
Get:53 http://us.archive.ubuntu.com trusty-backports/restricted Translation-en [28 B]
Get:54 http://us.archive.ubuntu.com trusty-backports/universe Translation-en [36.8 kB]
Hit http://us.archive.ubuntu.com trusty Release
Hit http://us.archive.ubuntu.com trusty/main Sources
Get:55 http://us.archive.ubuntu.com trusty/restricted Sources [5,433 B]
Hit http://us.archive.ubuntu.com trusty/universe Sources
Hit http://us.archive.ubuntu.com trusty/multiverse Sources
Hit http://us.archive.ubuntu.com trusty/main amd64 Packages
Get:56 http://us.archive.ubuntu.com trusty/restricted amd64 Packages [13.0 kB]
Hit http://us.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://us.archive.ubuntu.com trusty/multiverse amd64 Packages
Hit http://us.archive.ubuntu.com trusty/main i386 Packages
Get:57 http://us.archive.ubuntu.com trusty/restricted i386 Packages [13.4 kB]
Hit http://us.archive.ubuntu.com trusty/universe i386 Packages
Hit http://us.archive.ubuntu.com trusty/multiverse i386 Packages
Hit http://us.archive.ubuntu.com trusty/main Translation-en
Hit http://us.archive.ubuntu.com trusty/multiverse Translation-en
Hit http://us.archive.ubuntu.com trusty/restricted Translation-en
Hit http://us.archive.ubuntu.com trusty/universe Translation-en
Ign http://us.archive.ubuntu.com trusty/main Translation-en_US
Ign http://us.archive.ubuntu.com trusty/multiverse Translation-en_US
Ign http://us.archive.ubuntu.com trusty/restricted Translation-en_US
Ign http://us.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 7,330 kB in 43s (167 kB/s)
Reading package lists... Done
W: GPG error: https://apt.dockerproject.org ubuntu-trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F76221572C52609D
root@ubuntu02:~#

上面有报错,估计是https还需什么配置,如果你做得没有报错的话,接下来可以用这个命令去安装docker
#apt-get install -y docker-engine

我的有报错,所有我使用了另外一个方法如下:
其实这是只用了docker官方提供的脚本去安装docker ,
可以看到它自动解决了上来那个更新yum的错误。

8.开始安装当前最新版docker,也就是截止2017年12月19日最新版。
root@ubuntu02:~# curl -sSL https://get.docker.com/ | sh
#Executing docker install script, commit: 11aa13e

  • sh -c apt-get update -qq >/dev/null
    W: GPG error: https://apt.dockerproject.org ubuntu-trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F76221572C52609D
  • sh -c apt-get install -y -qq apt-transport-https ca-certificates curl software-properties-common >/dev/null
  • sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
  • sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty edge" > /etc/apt/sources.list.d/docker.list
  • [ ubuntu = debian ]
  • sh -c apt-get update -qq >/dev/null
  • sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
  • sh -c docker version
    Client:
    Version: 17.11.0-ce
    API version: 1.34
    Go version: go1.8.3
    Git commit: 1caf76c
    Built: Mon Nov 20 18:36:37 2017
    OS/Arch: linux/amd64

Server:
Version: 17.11.0-ce
API version: 1.34 (minimum version 1.12)
Go version: go1.8.3
Git commit: 1caf76c
Built: Mon Nov 20 18:35:10 2017
OS/Arch: linux/amd64
Experimental: false
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:

sudo usermod -aG docker your-user

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.
root@ubuntu02:~#

9.检查安装结果:
root@ubuntu02:~# docker --version
Docker version 17.11.0-ce, build 1caf76c

10.启动docker服务
root@ubuntu02:~# service docker start
docker start/running, process 9153

11.检查docker 服务
root@ubuntu02:~# service docker status
docker start/running, process 9153
root@ubuntu02:~# ps -ef | grep docker
root 9153 1 1 23:58 ? 00:00:00 /usr/bin/dockerd --raw-logs
root 9163 9153 0 23:58 ? 00:00:00 docker-containerd --config /var/run/docker/containerd/containerd.toml
root@ubuntu02:~# netstat -an | grep -i docker
unix 2 [ ACC ] STREAM LISTENING 17479 /var/run/docker.sock
unix 2 [ ACC ] STREAM LISTENING 17498 /var/run/docker/containerd/docker-containerd-debug.sock
unix 2 [ ACC ] STREAM LISTENING 17499 /var/run/docker/containerd/docker-containerd.sock
unix 2 [ ACC ] STREAM LISTENING 17506 /var/run/docker/metrics.sock
unix 2 [ ACC ] STREAM LISTENING 17718 /run/docker/libnetwork/599ee6e7c2726363158946e455d02cd7e48764d99b15dc68dd0ab29afe442b18.sock
unix 3 [ ] STREAM CONNECTED 17509 /var/run/docker/containerd/docker-containerd.sock
unix 3 [ ] STREAM CONNECTED 17515 /var/run/docker/containerd/docker-containerd.sock
unix 3 [ ] STREAM CONNECTED 17503 /var/run/docker/containerd/docker-containerd.sock

12.设置docker 开机自启动
root@ubuntu02:~# update-rc.d docker start 20 2 3 4 5 . stop 20 0 1 6 .
Adding system startup for /etc/init.d/docker ...
/etc/rc0.d/K20docker -> ../init.d/docker
/etc/rc1.d/K20docker -> ../init.d/docker
/etc/rc6.d/K20docker -> ../init.d/docker
/etc/rc2.d/S20docker -> ../init.d/docker
/etc/rc3.d/S20docker -> ../init.d/docker
/etc/rc4.d/S20docker -> ../init.d/docker
/etc/rc5.d/S20docker -> ../init.d/docker

13.从docker hub 仓管中拉取下载一个CentOS镜像
root@ubuntu02:~# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
85432449fd0f: Downloading 46.48MB/73.43MB
85432449fd0f: Pull complete
Digest: sha256:3b1a65e9a05f0a77b5e8a698d3359459904c2a354dc3b25ae2e2f5c95f0b3667
Status: Downloaded newer image for centos:latest

14.检查centos镜像是否已经下载成功
root@ubuntu02:~# docker images centos
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 3fa822599e10 2 weeks ago 204MB

15.进入centos 容器里
root@ubuntu02:~# docker run -i -t centos /bin/bash
[root@0ab2ed6ba9f7 /]# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 49G 1.7G 45G 4% /
tmpfs 64M 0 64M 0% /dev
tmpfs 240M 0 240M 0% /sys/fs/cgroup
/dev/sda2 49G 1.7G 45G 4% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 240M 0 240M 0% /proc/scsi
tmpfs 240M 0 240M 0% /sys/firmware
[root@0ab2ed6ba9f7 /]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@0ab2ed6ba9f7 /]# uname -r
4.4.0-31-generic
[root@0ab2ed6ba9f7 /]# uname -a
Linux 0ab2ed6ba9f7 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@0ab2ed6ba9f7 /]#

16.查看centos容器具体信息
root@ubuntu02:~# docker inspect centos
[
{
"Id": "sha256:3fa822599e10c5f2080dcf647068c72022b111d31bbec0c5adb8a96e7eb5379b",
"RepoTags": [
"centos:latest"
],
"RepoDigests": [br/>"centos@sha256:3b1a65e9a05f0a77b5e8a698d3359459904c2a354dc3b25ae2e2f5c95f0b3667"
],
"Parent": "",
"Comment": "",
"Created": "2017-11-30T00:13:33.787402963Z",
"Container": "2381448fe44a3c029b031a8125813a633338169a042a6b7d2c126ec65aa80523",
"ContainerConfig": {
"Hostname": "2381448fe44a",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:8c8d3fa42cc84aaec601101c70cf0b866764f2d490dd336a9cf98796774739c6",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"build-date": "20171128",
"license": "GPLv2",
"name": "CentOS Base Image",
"vendor": "CentOS"
}
},
"DockerVersion": "17.06.2-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:8c8d3fa42cc84aaec601101c70cf0b866764f2d490dd336a9cf98796774739c6",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"build-date": "20171128",
"license": "GPLv2",
"name": "CentOS Base Image",
"vendor": "CentOS"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 203545788,
"VirtualSize": 203545788,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/090c562b6617cfb17df1e791a594f561c54b1611e131baf9ada1fd4ba0e03b1d/merged",
"UpperDir": "/var/lib/docker/overlay2/090c562b6617cfb17df1e791a594f561c54b1611e131baf9ada1fd4ba0e03b1d/diff",
"WorkDir": "/var/lib/docker/overlay2/090c562b6617cfb17df1e791a594f561c54b1611e131baf9ada1fd4ba0e03b1d/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:d1be66a59bc56bb90e92c3d4742ce73dcb5f62acc6e92de55039e21957ed5d23"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
root@ubuntu02:~#

上面结果表明已经成功。

后续会持续更新docker 高级实战内容。

本人其实想写一本书的。慢慢来吧。