1、准备环境
centos7版本上安装docker,6版本的安装有很多依赖要装,所以需要先在vm中创建一个centos7版本的虚拟机。如何在vm中搭建一个虚拟机,这里就不赘述了。
2、安装步骤:
在安装之前我们可以看一下官网是如何介绍的:
centos7上安装docker
2.1、如果之前安装过docker,这里需要卸载掉之前安装痕迹。
yum remove docker \
docker-common \
docker-selinux \
docker-engine
2.2、安装依赖
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2.3、使用以下命令来设置稳定的存储库。 即使您想从边缘或测试存储库安装构建,也总是需要稳定的存储库。(谷歌翻译官网)
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
2.4、安装最新版本
yum install docker-ce
2.5、启动docker
systemctl start docker
查看版本:
这里注意:后面在这个基础上安装k8s时候会报错,
Error: docker-ce conflicts with 2:docker-1.12.6-68.gitec8512b.el7.centos.x86_64
解决方案:
换了一种安装方式直接yum install docker,安装后的版本是1.12.6,后续在安装k8s的时候没有报错了,先就这样了,等后续熟悉docker再来完善文档。
2.6、验证docker是否安装成功
[root@bfd-v7 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
3、docker的基本概念
Docker 包括三个基本概念
- 镜像(Image)
- 容器(Container)
- 仓库(Repository)
理解了这三个概念,就理解了 Docker 的整个生命周期。
Docker 镜像就是一个只读的模板。
例如:一个镜像可以包含一个完整的 ubuntu 操作系统环境,里面仅安装了 Apache 或用户需要的其它应用程序。
容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全
的平台。
仓库是集中存放镜像文件的场所。有时候会把仓库和仓库注册服务器(Registry)混为一谈,并不严格区。
分。实际上,仓库注册服务器上往往存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像有不同的
标签(tag)。
4、docker的一些简单指令使用,以此来验证docker安装的正确性。
4.1、pull指令,用来获取一个镜像。
[root@bfd-v7 dl]# docker pull ubuntu:12.04
4.2、运行该镜像,则会产生一个容器。
[root@bfd-v7 dl]# docker run -t -i ubuntu:12.04 /bin/bash
root@88e0f3e91586:/#
可以看到是一个ubuntu的系统。
至此,我们可以看出docker已经安装成功,并能够使用。
5、在安装或者启动中容易出现的问题
在后续你可能多次安装各种版本,以及在启动的时候出现的问题,当你卸载 后重装发现也是解决不了。
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
详细错误如下图:
解决方案:
重点内容
1、看看有没有这个文件夹 /var/run/docker.sock,如果有的话删掉,再启动就可以了,可能之前安装过启动的进程没有停止。
2、查看文件系统 /etc/docker/daemon.json 有没有这个文件,没有测创建它包括二级目录 docker
在daemon.json文件中输入以下内容:
{ "storage-driver": "devicemapper" }
我的问题就是这个原因导致,之前在看到资料中有一个配置了docker加速,配置后会在daemon.json后面追加的。但是这次不知道怎么里面的内容没了。(可能多次重装导致的)
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://04be47cf.m.daocloud.io