本文将演示在Oracle云上的Oracle Linux 6的实例上安装和配置Docker Engine。
首先,在Oracle云上创建Oracle Linux 6.8的实例,(略过创建过程,具体流程参见本公众号的其他文章《在Oracle云上创建Oracle Linux实例》),同时为该实例新建一块50G的硬盘,专门用于存放Docker Engine的文件系统,(具体流程参加本公众号的其他文章《为Oracle云上的Linux实例新增硬盘》):
操作系统版本情况:
[root@ef5723 ~]# uname -a
Linux ef5723 4.1.12-61.1.33.el6uek.x86_64 #2 SMP Thu Mar 30 18:39:45 PDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@ef5723 ~]# cat etc/oracle-release
Oracle Linux Server release 6.8
文件系统和新增磁盘:
[root@ef5723 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root
45G 969M 42G 3%
tmpfs 7.4G 0 7.4G 0% dev/shm
/dev/xvdb1 477M 69M 379M 16% boot
[root@ef5723 ~]# fdisk -l dev/xvdc
Disk /dev/xvdc: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes 512 bytes
I/O size (minimum/optimal): 512 bytes 512 bytes
Disk identifier: 0x00000000
在Oracle Linux上,Docker 1.9(含1.9)以后的版本对操作系统内核有要求,只支持内核Unbreakable Enterprise Kernel Release 4 (UEK R4),因此在安装和配置Docker 1.9以上版本前,需要将操作系统的内核升级到UEK R4。
一、升级操作系统内核
本文将介绍采用yum升级操作系统内核。
修改yum repository配置文件,配置文件位于目录 /etc/yum.repos.d/下,Oracle Linux 6的yum repository文件为public-yum-ol6.repo
[root@ef5723 opc]# cd /etc/yum.repos.d/
[root@ef5723 yum.repos.d]# ls
ksplice-uptrack.repo public-yum-ol6.repo
修改public-yum-ol6.repo配置文件,如下:
禁用以下repo,将enabled项置为0
[ol6_UEKR3_latest]name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/UEKR3/latest/$basearch/gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oraclegpgcheck=1enabled=0[ol6_UEK_latest]name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/UEK/latest/$basearch/gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oraclegpgcheck=1enabled=0
启用以下repo,将enabled项设置为1:
[ol6_UEKR4]name=Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux $releasever ($basearch)baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/UEKR4/$basearch/gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oraclegpgcheck=1enabled=1
[ol6_addons]name=Oracle Linux $releasever Add ons
($basearch)baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/addons/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
[public_ol6_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
将系统内核升级到UEK R4:
# yum update
重启操作系统,以内核UEK R4启动
# reboot
注:在重启操作系统前,确认系统的缺省启动内核,查看配置系统启动配置文件/boot/grub/grub.conf,确保缺省内核为UEK R4。
二、安装Docker Engine
确认是以UEK R4内核启动后,准备安装Docker Engine。
采用root安装Docker Engine,执行以下命令
# yum install docker-engine
三、安装btrfs文件系统
Oracle推荐采用btrfs文件系统安装docker,
详情参见:https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/.
安装btrfs包,
# yum install btrfs-progs
配置btrfs文件系统
注:本实验中,为docker单独分配了一个磁盘卷/dev/xvdc,接下来将在该磁盘卷上创建btrfs文件系统,这也是在Oracle Linux上安装配置Docker的最佳实践:为docker分配一个专属的btrfs文件系统。
# mkfs.btrfs /dev/xvdc
[root@ef5723 opc]# mkfs.btrfs /dev/xvdc
Detected a SSD, turning off metadata duplication. Mkfs with -m dup if you want to force metadata duplication.
btrfs-progs v4.2.2
See http://btrfs.wiki.kernel.org for more information.
WARNING: The skinny-metadata mkfs default feature will work with the current kernel, but it is not compatible with older kernels supported on this OS. You can disable it with -O ^skinny-metadata option in mkfs.btrfs
WARNING: The extref mkfs default feature will work with the current kernel, but it is not compatible with older kernels supported on this OS. You can disable it with -O ^extref option in mkfs.btrfs
Label: (null)
UUID: ad7bbc29-45f8-4657-8e82-5fc1e8ef7868
Node size: 16384
Sector size: 4096
Filesystem size: 50.00GiB
Block group profiles:
Data: single 8.00MiB
Metadata: single 8.00MiB
System: single 4.00MiB
SSD detected: yes
Incompat features: extref, skinny-metadata
Number of devices: 1
Devices:
ID SIZE PATH
1 50.00GiB /dev/xvdc
四、加载Docker文件系统
创建加载点/var/lib/docker,将已创建的btrfs文件加载到该加载点,并设置自动加载
# mkdir /var/lib/docker
# mount
/dev/xvdc /var/lib/docker
设置自动加载
编辑文件/etc/fstab,添加以下记录:
/dev/xvdc /var/lib/docker btrfs defaults 0 0
查看文件系统加载状态:
[root@ef5723 opc]# mount
/dev/mapper/vg_main-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/xvdb1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
xenfs on /proc/xen type xenfs (rw)
/dev/xvdc on /var/lib/docker type btrfs (rw)
五、启动Docker Engine服务
启动Docker Engine服务,并将该服务设置为随机自启动。
# service docker start
# chkconfig docker on
查看Docker Engine服务的状态和Docker的版本信息
[root@ef5723 opc]# service docker status
docker (pid 2461) is running...
[root@ef5723 opc]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.12.6
Storage Driver: btrfs
Build Version: Btrfs v4.2.2
Library Version: 101
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: null overlay host bridge
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options:
Kernel Version: 4.1.12-94.3.5.el6uek.x86_64
Operating System: Oracle Linux Server 6.9
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 14.69 GiB
Name: ef5723
ID: 7VVR:JGHJ:JZ6J:6ZQR:ZNWQ:I7JN:VXR6:DT5X:C7V2:U4KI:T3CV:RNML
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry:https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8
[root@ef5723 opc]# docker version
Client:
Version: 1.12.6
API version: 1.24
Go version: go1.6.4
Git commit: 1512168
Built: Wed Jan 11 09:49:56 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Go version: go1.6.4
Git commit: 1512168
Built: Wed Jan 11 09:49:56 2017
OS/Arch: linux/amd64
六、启动第一个容器
登录Docker Hub,从Hub上下载镜像,启动容器。
如需从Docker Hub上下载镜像,需提前在Docker Hub上注册账号,
详情参见:
https://hub.docker.com
登录Docker Hub:
[root@ef5723 opc]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: cheneyyu8282
Password:
Login Succeeded
搜索相关镜像
[root@ef5723 opc]# docker search hello
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Docker... 309 [OK]
tutum/hello-world Image to test docker deployments. Has Apac... 35 [OK]
google/nodejs-hello 15 [OK]
dockercloud/hello-world Hello World! 12 [OK]
google/golang-hello 8 [OK]
下载镜像
[root@ef5723 opc]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest
[root@ef5723 opc]#
查看镜像:
[root@ef5723 opc]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 4 months ago 1.84 kB
启动容器
[root@ef5723 opc]# 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.
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
现在,我们就可以愉快的开始Docker之旅!