Docker 入门简介

什么是Docker?

1)Docker 是世界领先的软件容器平台。
2)Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核 的cgroup,namespace,以及AUFS类的UnionFS等技术,对进程进行封装隔离,属于操作系统层面的虚拟化技术。 由于隔离的进程独立于宿主和其它的隔离的进 程,因此也称其为容器。Docke最初实现是基于 LXC.
3)Docker 能够自动执行重复性任务,例如搭建和配置开发环境,从而解放了开发人员以便他们专注在真正重要的事情上:构建杰出的软件。
4)用户可以方便地创建和使用容器,把自己的应用放入容器。容器还可以进行版本管理、复制、分享、修改,就像管理普通的代码一样。

目前最新docker分为 docker-ce和docker-ee两个版本,其中ce为社区版免费的,ee为商业版商用的,目前测试用ce版本。

安装

sudo apt-get install -y docker.io
把用户加入到docker组,避免运行docker需要sudo权限.
sudo usermod -aG docker hhs

测试是否运行成功

1
sudo docker run hello-world

如果出现:

1
2
3
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

这是因为docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取镜像,出现这个问题的原因:是应为docker服务器在国外,我们在国内无法正常拉取镜像,所以就需要我们为docker设置国内阿里云的镜像加速器;所以需要增加/etc/docker/daemon.json配置文件设置为阿里云镜像.

1
2
3
{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}

如果出现如下打印,说明成功.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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/

基本使用