检查系统版本及内核
# uname -r
2.6.32-431.el6.x86_64
# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
安装Docker
使用其他的安装源可能会导致Docker与内核版本不一致
# rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
......
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
......
# yum -y install docker-io
......
验证Docker
执行docker 会输出帮助说明Docker已经成功安装了
# docker
Usage: docker [OPTIONS] COMMAND [arg...]
......
启动并设置开机自启动
# service docker start
Starting cgconfig service: [确定]
Starting docker: [确定]
# chkconfig docker on
此时docker并没有启动成功
# service docker status
docker 已死,但 pid 文件仍存
启动失败原因是
WARN[0000] You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.10.0.
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
docker: relocation error: docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
通过对依赖的升级解决以上问题
# yum -y upgrade device-mapper-libs
再次尝试启动docker服务
# service docker start
Starting docker: [确定]
检查服务状态
# service docker status
docker (pid 24471) 正在运行...
获取第一个镜像
获取一个Alpine linux,仅有5M大的linux
# docker pull alpine
latest: Pulling from alpine
28a0c8bbcab3: Pull complete
9797e5e798a0: Pull complete
Digest: sha256:ed8059bd90dd8cd6b7bfddedc7bba0f7555f766a00daf6a6efc86fa3339c09ef
Status: Downloaded newer image for alpine:latest
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
alpine latest 9797e5e798a0 7 days ago 4.143 MB
创建一个容器并启动一个容器
使用之前获取的Alpine镜像创建一个容器,并制定容器名为 AlpineLinux
# docker run -i -t --name=AlpineLinux alpine /bin/sh
/ #
退出容器
- 使用 exit 指令退出,退出同时会结束当前的容器
- 使用
CTRL
+P
+Q
退出容器并保持当前容器状态
详细docker命令及使用请查阅: Docker中文