Docker Engine安装配置
以下描述仅Docker在Ubuntu Precise 12.04 (LTS)、Ubuntu Trusty 14.04 (LTS)、Ubuntu Wily 15.10上的安装配置过程。其他类型的操作系统,请参考Docker官网:https://docs.docker.com/
内核升级
Docker要求Linux内核至少在3.10以上。查看系统内核版本:
# uname -r 3.16.0-30-generic |
如果不满足,需要升级系统内核。系统版本不同,升级方式、升级内容有差异。查看操作系统版本:
# cat /etc/issue Ubuntu 14.04.2 LTS \n \l |
升级步骤:
- Ubuntu Precise 12.04 (LTS)
# sudo apt-get update # sudo apt-get install linux-image-generic-lts-trusty -y # sudo apt-get install linux-headers-generic-lts-trusty -y # sudo reboot # uname -r |
- Ubuntu Trusty 14.04 (LTS)、Ubuntu Wily 15.10
# sudo apt-get update # sudo apt-get install linux-image-extra-$(uname -r) -y # sudo apt-get install apparmor -y # sudo reboot # uname -r |
更新apt源
# sudo apt-get install apt-transport-https ca-certificates -y # sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
- Ubuntu Precise 12.04 (LTS)
# sudo bash -c "echo deb https://apt.dockerproject.org/repo ubuntu-precise main > /etc/apt/sources.list.d/docker.list" |
- Ubuntu Trusty 14.04 (LTS)
# sudo bash -c "echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list" |
- Ubuntu Wily 15.10
# sudo bash -c "echo deb https://apt.dockerproject.org/repo ubuntu-wily main > /etc/apt/sources.list.d/docker.list" |
开始更新:
# sudo apt-get update |
如果安装过旧版本,卸载:
# sudo apt-get purge lxc-docker |
安装Docker Engine
# sudo apt-get install docker-engine # sudo service docker start |
验证:
# sudo docker run hello-world |
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message. Then, it exits.
其他配置
1.4.1、打开memory、swap计量开关
编辑 /etc/default/grub 文件,
设置 GRUB_CMDLINE_LINUX 如下:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" |
保存关闭,更新GRUB,重启生效:
# sudo update-grub # sudo reboot |
1.4.2、配置添加DNS(临时DNS,后续IP可能变化)
编辑 vi /etc/resolvconf/resolv.conf.d/head 文件,添加nameserver如下:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 10.5.24.31 |
执行如下命令:
# resolvconf -u |
检查 /etc/resolv.conf 文件是否更新:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 10.5.24.31 nameserver 10.7.7.1 nameserver 8.8.8.8 search lab.intra.nsfocus.com |
编辑 /etc/default/docker 文件,修改Docker启动参数,添加DNS:
DOCKER_OPTS="--dns 8.8.8.8 --dns 10.5.24.31 |
重启Docker进程:
# sudo restart docker |
1.4.3、配置Docker开机自启
- Ubuntu Trusty 14.04 (LTS)、Ubuntu Precise 12.04 (LTS)——默认开机自启
- Ubuntu Wily 15.10
# sudo systemctl enable docker |
1.4.4、配置添加insecure-registry(临时registry,后续地址可能变化)
编辑 /etc/default/docker 文件,修改Docker启动参数,添加insecure-registry:
DOCKER_OPTS="--dns 8.8.8.8 --dns 10.5.24.31 --insecure-registry=10.5.24.46:80" |
重启Docker进程:
# sudo restart docker |
验证是否生效:
# docker run -it 10.5.24.46:80/docker/ubuntu:14.04 /bin/bash -c 'echo helloworld' |
1.5、Ubuntu安装配置官方文档
参考资料:https://docs.docker.com/engine/installation/linux/ubuntulinux/