docker'部署

环境:ubuntu-14.04.4-server-amd64
1、更换阿里云源
备份源配置文件:
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
$ sudo vim /etc/apt/sources.list
删除文件内容,更新为:
deb http://mirrors.aliyun.com/ubuntu trusty main restricted
deb-src http://mirrors.aliyun.com/ubuntu trusty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu trusty-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu trusty-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu trusty universe
deb-src http://mirrors.aliyun.com/ubuntu trusty universe
deb http://mirrors.aliyun.com/ubuntu trusty-updates universe
deb-src http://mirrors.aliyun.com/ubuntu trusty-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.aliyun.com/ubuntu trusty multiverse
deb-src http://mirrors.aliyun.com/ubuntu trusty multiverse
deb http://mirrors.aliyun.com/ubuntu trusty-updates multiverse
deb-src http://mirrors.aliyun.com/ubuntu trusty-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu trusty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
执行如下命令刷新:
$ sudo apt-get clean
$ sudo apt-get update

2、检查内核版本:
$ uname -r
4.2.0-27-generic

3、更新包信息确保APT工作于https模式并且安装好CA证书:
$ sudo apt-get update
$apt-get install apt-transport-https ca-certificates

4、增加一个新GPG密钥:
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

5、新建docker.list文件并加入相关内容:
$ sudo vim /etc/apt/sources.list.d/docker.list
deb https://apt.dockerproject.org/repo ubuntu-trusty main
更新APT软件包索引:
$ atp-get update
假如存在旧的repo则清除:
$ apt-cache policy docker-engine
验证APT是否从正确的库中获取:
$ apt-get purge lxc-docker
此命令下载一个测试图像并运行于一个容器中,它将打印一份欣喜然后自动退出。

6、安装linux-image-extra kernel package
$ sudo apt-get update
$ sudo apt-get install linux-image-extra-$(uname -r)
检查是否有安装apparmor
$ whereis apparmor
没有的话
$ apt-get install -y apparmor
$ sudo reboot

7、进入docker安装阶段
$ sudo apt-get update
安装docker
$ sudo apt-get install docker-engine
启动docker服务
$ sudo service docker start
验证docker安装是否OK
$ sudo docker run hello-world

8、创建一个docker组并加入当前用户
$ sudo usermod -aG docker ubuntu
验证
$ docker run hello-world

9、调整内存和交换分区
当运行docker出现如下报错:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.
需要做如下操作:
$ sudo vim /etc/default/grub
设置GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
$ sudo update-grub
$ sudo reboot

10、开启UFW转发
检查UFW是否安装并启动
$ sudo ufw status
$ sudo vim /etc/default/ufw
设置DEFAULT_FORWARD_POLICY="ACCEPT"
重启UFW服务并使用新的配置
$ sudo ufw reload
放行2375端口
$ sudo ufw allow 2375/tcp

11、配置DNS服务器
当用台式机启动容器时报错:
WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers
can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
$ sudo vim /etc/default/docker
设置DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
重启docker守护进程
$ sudo restart docker
关闭dnsmasq
$ sudo vim /etc/NetworkManager/NetworkManager.conf
注释掉dns=dnsmasq
保存后重启NetworkManager和Docker
$ sudo restart network-manager
$ sudo restart docker

12、Ubuntu14.04.4版本安装docker后会将其服务设为开机自启动。
升级docker
$ sudo apt-get upgrade docker-engine
卸载docker包
$ sudo apt-get purge docker-engine
$ sudo apt-get autoremove --purge docker-engine
删除镜像、容器、卷
$ rm -rf /var/lib/docker
同时你需要手动删除用户生成的配置文件,此略!!!

上一篇:Your awesome titleHH


下一篇:Java的static和final关键字的用法