Docker | Install
Contents
简介
本文基于Ubuntu16.04_64bit_OS 和 CentOS7_64bit_OS
查看系统信息
- $ uname -a
Linux device_name 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
- $ uname -a
使用root账号进行安装
安装前准备
Ubuntu
升级包管理器
$ apt-get update
$ apt-get upgrade
安装其他包
基本Linux内核镜像,内置了AUFS
1 2 3 |
$ apt-get install linux-image-generic-lts-trusty $ apt-get install -y --install-recommends linux-generic-lts-xenial $ reboot |
Centos
更新系统
$ yum upgrade -y
安装Docker
Docker自动安装脚本
下载安装
1 2 3 4 5 6 7 8 9 10 |
$ curl -sSL https://get.docker.com/ | sh // 官方 $ wget -qO- https://get.docker.com/ | sh // 获取最新版 # 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! # 安装完成后执行如下命令 $ usermod -aG docker $USER |
查看安装版本
1 2 3 4 5 6 7 8 9 10 11 |
$ docker version Client: Version: 17.03.1-ce API version: 1.27 Go version: go1.7.5 Git commit: c6d412e Built: Fri Mar 24 00:40:33 2017 OS/Arch: linux/amd64 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? * 此问题是因为没有建立docker用户组而导致的,解决方法参考·建立Docker用户组 |
建立Docker用户组
注意:
- docker群组相当于root用户
docker
默认使Unix Socket与Docker引擎通信,而只有root和docker组的用户才可以访问Docker引擎的Unix Socket
1 2 3 4 5 |
# 建立docker用户组 $ groupadd docker # 将当前账号加入docker组 $ usermod -aG docker $USER |
调整内存和交换空间(GRUB)
centos不需要配置这一步
在Docker使用过程中可能出现下面信息
WARNING
:原因是没有开启内存和交换空间,即要修改系统的GUN GRUB(GUN Grand Unified Bootloader)1
WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
开启GRUB步骤如下:
1 2 3 4 5 6 7 8 9
# 编辑GRUB配置文件 $ gedit /etc/default/grub # 设置GRUB_CMDLINE_LINUX的值如下 $ GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" //配置后的结果见下图 # 更新GRUB $ update-grub $ reboot
GRUB Config File
没有开启内存和交换空间 Issue & Solution
阿里云安装脚本
1 2 |
$ curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh - $ docker version |
DaoCloud安装脚本
1 2 |
$ curl -sSL https://get.daocloud.io/docker | sh $ docker version |
FAQ
Docker守护进程启动失败
只有root和docker组的用户才可以访问Docker引擎的Unix Socket,出现如下错误则是当前用户没有添加到docker用户组导致
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Q: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. A: root@boyzhe:~# usermod -aG docker $USER root@boyzhe:~# reboot root@boyzhe:~# docker version Client: Version: 17.03.1-ce API version: 1.27 Go version: go1.7.5 Git commit: c6d412e Built: Fri Mar 24 00:40:33 2017 OS/Arch: linux/amd64 Server: Version: 17.03.1-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: c6d412e Built: Fri Mar 24 00:40:33 2017 OS/Arch: linux/amd64 Experimental: false |
没有开启内存和交换空间
1 2 3 4 5 |
Q: root@boyzhe:~# docker run -d --name web -m 512m -p 8080:80 joshhu/webdemo Status: Downloaded newer image for joshhu/webdemo:latest WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap. A: 参考上文:调整内存和交换空间(GRUB) |