Docker概念及安装(ubuntu 18.04)
Docker基本概念与安装部署
概念
Docker 是一个开源的应用容器引擎,基于Go 语言并遵从 Apache2.0 协议开源。
Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销低,速度快,镜像多。
Linux容器是Linux的一种虚拟化技术,可以简单将Docker理解为轻量级的虚拟机,但是 Linux容器不是模拟一个完整的操作系统,而是对进程进行隔离,相当于是在正常进程的外面套了一个保护层。对于容器里面的进程来说,它接触到的各种资源都是虚拟的,从而实现与底层系统的隔离。
与虚拟机相比较
| 功能对比 | Docker容器 | VM虚拟机 |
|---|---|---|
| 启动时间 | 秒级 | 分钟级 |
| 硬盘使用 | 一般为MB | 一般为GB |
| 性能 | 接近原生 | 弱于 |
| 系统支持量 | 单机支持上千个容器 | 一般是几十个 |
Docker 主要包括三个部分
Image(镜像) —>核心Container(容器)Repository(仓库)
简单来说,镜像是 Docker 运行容器的前提,仓库是存放镜像的场所。详细部分在日后再总结。
Docker 分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版)。
**这里主要介绍Docker在fabric中的应用 **
不得不说这里有些复杂,加上在我的垃圾笔记本上运行VM(在虚拟机上运行“虚拟机“......)卡的一批,于是在fabric部署这里疯狂踩坑.....好了,这里主要写一下Docker安装与配置
安装
**声明:操作系统采用的 Ubuntu 18.04 **
- 首先检查Ubuntu系统内核版本,保证版本在3.10以上的64bit系统,我的是4.15:
uname -r
- 使用root权限用户登入终端:
sudo su root
- 更新apt-get,保证其是最新版本(我在虚拟机上更新貌似有点问题,不知是网络原因还是源的问题,但对安装系统自带包影响不大):
apt-get update
- 使用系统自带的docker安装包进行安装(可能不是docker的最新版本,我选择安装这个,最新的一直安装失败,无论国内源还是国外源....最新版本安装可参见网上教程):
apt-get install -y docker.io
- 查看是否安装成功:
docker version
# docker -v 只显示docker版本
- 启动docker服务(此为ubuntu版本,其它系统与此不同)
service docker start
#重启docker服务,一般更改配置后使用
service docker restart
#关闭docker服务
service docker stop
获取镜像
- 我们需要把官方镜像hello-world拉下来:
docker pull hello-world
- 查看本地所有拉取的镜像:
docker images
- 启动镜像 hello-world:
docker run hello-world
- 输出这些内容表示安装成功:
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
相关配置及问题解决
-
出现错误(该错误影响我良久):
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) #在等待报头时超时, 请求在等待连接时被取消(客户端)。Docker 默认的源为国外官方源,下载速度较慢,可改为国内镜像源。网上方法一般是修改 daemon.json 文件,但我加入阿里源之后直接无法拉取任何镜像了.... -
可能是docker还没有运行,需要
server docker startGot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denie #Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? -
出现错误,源有错误,添加国内源(百度,但我试了下没用....)or在之前执行
sudo su rootJob for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
实例1
#拉取镜像ubuntu
docker pull ubuntu
#运行 echo hello docker hellp 命令
docker run ubuntu echo hello docker
#输出
hello docker
总结
此次安装其实还存在许多问题,比如国外镜像源,拉个镜像需要好几个小时还未必成功(有梯子另算),而且第一次启动OK,但后面会发生莫名其妙的无法再启动Docker...
打算用CentOS7再重新安装一遍

浙公网安备 33010602011771号