docker
是什么?docker 起初是dotCloud公司的一个业余项目, 是基于Go和LXC实现的一个轻量级的操作系统虚拟化方案。他可以实现更快的交付部署、更高效的虚拟化、更耿丹的迁移拓展和管理等,具体的在后面会慢慢体会到。首先我们先要把 docker 装到你的机子上,下面以 ubuntu 为例:
docker 获取安装
最新的安装说明, 请查阅 官方文档
首先查看 ubuntu 发行版本号, 文档上针对不同版本的系统会有一些注意事项。
$ uname -r |
导入 apt key:
$ sudo apt-get update |
选择对应的仓库, 根据 Ubuntu version 选择 Repository:
- Precise 12.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-precise main
- Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main
- Wily 15.10 deb https://apt.dockerproject.org/repo ubuntu-wily main
- Xenial 16.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-xenial main
选择后, 写入 docker.list:
$ echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list |
对于以下版本:
- Ubuntu Xenial 16.04 (LTS)
- Ubuntu Wily 15.10
- Ubuntu Trusty 14.04 (LTS)
推荐安装 linux-image-extra-*
内核包, 因为 linux-image-extra-*
包允许你使用 aufs
存储驱动.
安装如下:
$ sudo apt-get update |
安装 docker-engine:
$ sudo apt-get update |
hello-world 测试一下 docker 运行情况
由于本地没有hello-world
这个image, docker会去远程搜索并拉取下来。
$ sudo docker run hello-world |
Hello from Docker!
This message shows that your installation appears to be working correctly.
恭喜你, docker 正常工作。
其他
docker user
docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.
因为 docker daemon 绑定了unix socket 而不是 tcp socket, 而 Unix socket 一般被root所拥有,正因如此,docker daemon 总是以root身份运行。
为了避免总是使用sudo
来执行, 可以创建一个docker
group, 当 docker daemon 启动时, 会使 Unix socket 的 read/writable 拥有权设为 docker
组.
$ sudo groupadd docker |
上面不用sudo
来 run hello-world, 如果失败, 会有类似下面的提示:
Cannot connect to the Docker daemon. Is 'docker daemon' running on this host? |
卸载
移除 docker-engine 包: |
异常情况
异常:执行用户不在docker组
如果不能run,提示Cannot connect to the Docker daemon. Is the docker daemon running on this host
,可能是没有把当前用户加入docker组。
sudo usermod -aG docker your-user
Log out and log back in
异常:服务未启动
docker run hello-world
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
sudo service docker start |
参考
https://docs.docker.com/linux/started/
https://docs.docker.com/engine/installation/linux/ubuntulinux/