Docker | Install
source link: https://ijayer.github.io/post/tech/devops/docker/20170408-docker-01-install/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
本文基于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
$ 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自动安装脚本
$ 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 |
查看安装版本
$ 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
# 建立docker用户组 $ groupadd docker # 将当前账号加入docker组 $ usermod -aG docker $USER |
调整内存和交换空间(GRUB)
centos不需要配置这一步
在Docker使用过程中可能出现下面信息
WARNING
:原因是没有开启内存和交换空间,即要修改系统的GUN GRUB(GUN Grand Unified Bootloader)WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
开启GRUB步骤如下:
# 编辑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
阿里云安装脚本
$ curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh - $ docker version |
DaoCloud安装脚本
$ curl -sSL https://get.daocloud.io/docker | sh $ docker version |
Docker守护进程启动失败
只有root和docker组的用户才可以访问Docker引擎的Unix Socket,出现如下错误则是当前用户没有添加到docker用户组导致
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 |
没有开启内存和交换空间
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) |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK