========================安装篇====================================
被墙了,弄了半天放弃了,直接用deb安装
1.下载:
2.
Install from a package
If you cannot use Docker’s repository to install Docker CE, you can dow
nload the
.deb
file for you
r release and install it manually. You need to download a new file each time you want to upgrade Docker CE.
- Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, browse to pool/stable/ and choose amd64, armhf, ppc64el, or s390x. Download the .deb file for the Docker version you want to install.
Note
: To install an
edge
package, change
the word
stable
in the URL to
edge
.
Learn about stable and edgechannels
.
- Install Docker CE, changing the path below to the path where you downloaded the Docker package.
$
sudo
dpkg
-i
/path/to/package.deb
The Docker daemon starts automatically.
- Verify that Docker CE is installed correctly by running the hello-world image.
$
sudo
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
Docker CE is installed and running. The
docker
group is created but no users are added to it. You need to use
sudo
to run Docker commands. Cont
inue to
Post-installation steps for Linux
to allow non-privileged users to run Docker commands and for other optional configuration steps.
=========================使用篇
====================================
Docker 是什么?
Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接口。它是目前最流行的 Linux 容器解决方案。
Docker 将应用程序与该程序的依赖,打包在一个文件里面。运行这个文件,就会生成一个虚拟容器。程序在这个虚拟容器里运行,就好像在真实的物理机上运行一样。有了 Docker,就不用担心环境问题。
总体来说,Docker 的接口相当简单,用户可以方便地创建和使用容器,把自己的应用放入容器。容器还可以进行版本管理、复制、分享、修改,就像管理普通的代码一样。
由于 Docker 确保了执行环境的一致性,使得应用的迁移更加容易。Docker 可以在很多平台上运行,无论是物理机、虚拟机、公有云、私有云,甚至是笔记本,其运行结果是一致的。因此用户可以很轻易的将在一个平台上运行的应用,迁移到另一个平台上,而不用担心运行环境的变化导致应用无法正常运行的情况。
Docker 的用途
Docker 的主要用途,目前有三大类。
(1)
提供一次性的环境。比如,本地测试他人的软件、持续集成的时候提供单元测试和构建的环境。
(2)
提供弹性的云服务。因为 Docker 容器可以随开随关,很适合动态扩容和缩容。
(3)
组建微服务架构。通过多个容器,一台机器可以跑多个服务,因此在本机就可以模拟出微服务架构。
Docker 包括三个基本概念
- 镜像(Image)
- 容器(Container)
- 仓库(Repository)
理解了这三个概念,就理解了 Docker 的整个生命周期。
Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。镜像不包含任何动态数据,其内容在构建之后也不会被改变。
镜像(
Image
)和
容器(
Container
)
的关系,就像是面向对象程序设计中的
类
和
实例
一样,镜像是静态的定义,
容器是镜像运行时的实体。
容器可以被创建、启动、停止、删除、暂停等。
一个
Docker Registry
中可以包含多个
仓库
(
Repository
);每个仓库可以包含多个
标签
(
Tag
);每个标签对应一个镜像。
Docker Registry 公开服务
Docker Registry 公开服务是开放给用户使用、允许用户管理镜像的 Registry 服务。一般这类公开服务允许用户免费上传、下载公开的镜像,并可能提供收费服务供用户管理私有镜像。
最常使用的 Registry 公开服务是官方的
Docker Hub
,这也是默认的 Registry,并拥有大量的高质量的官方镜像。除此以外,还有
CoreOS
的
Quay.io
,CoreOS 相关的镜像存储在这里;Google 的
Google Container Registry
,
Kubernetes
的镜像使用的就是这个服务。
由于某些原因,在国内访问这些服务可能会比较慢。国内的一些云服务商提供了针对 Docker Hub 的镜像服务(
Registry Mirror
),这些镜像服务被称为
加速器
。常见的有
阿里云加速器
、
DaoCloud 加速器
等。使用加速器会直接从国内的地址下载 Docker Hub 的镜像,比直接从 Docker Hub 下载速度会提高很多。在
安装 Docker
一节中有详细的配置方法。
====================镜像加速=============================
镜像加速器
国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务,例如:
我们以 Docker 官方加速器为例进行介绍。
Ubuntu 14.04、Debian 7 Wheezy
DOCKER_OPTS=
"--registry-mirror=https://registry.docker-cn.com"
重新启动服务。
$ sudo service docker restart
======================参考链接===================================
http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html