您的位置:首页 > 运维架构 > Docker

Docker-简介和安装

2017-07-03 09:38 405 查看
一.简介和概念

docker:开发.容纳.运行应用程序的平台

docker 平台:在容器中安全的隔离运行

Docker引擎:cs结构的程序

1. server:长时间运行守护的程序

2. Rest API

3. CLI:command line命令行

docker对象:

images

containers

networks

data volumes





Docker daemon:

docker的守护进程

运行在host之上,不需要直接交互,通过cli访问

Docker client:客户端

1.接受用户指令并和docker守护进程通信.

Docker images:

只读模板,build构建镜像,只读的方式

Docker registries:

注册表,包含镜像的库

Docker containers:

通过镜像创建容器,每个容器是独立.安全的运行平台.容器中运行的docker的主键

工作方式:分层

官网文档

https://docs.docker.com/engine/docker-overview/#the-docker-client


二.ubuntu下安装Docker

安装的环境要求:64为位操作系统,内核为3.10以上的版本

查看内核的版本

sulei@sulei:~$ uname -r
4.4.0-78-generic


1.安装Docker引擎

1.准备

a.检查内核版本

2.更新apt软件源

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates


3.添加GPG key


sulei@sulei:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
Executing: /tmp/tmp.BA5ij4R5P0/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv-keys
36A1D7869245C8950F966E92D8576A8BA88D21E9
gpg: 下载密钥‘A88D21E9’,从 hkp 服务器 keyserver.ubuntu.com
gpg: 密钥 A88D21E9:公钥“Docker Release Tool (releasedocker) <docker@dotcloud.com>”已导入
gpg: 合计被处理的数量:1
gpg:               已导入:1  (RSA: 1)


4.配置docker软件源文件


sulei@sulei:~$ cd /etc/apt/sources.list.d/docker.list
bash: cd: /etc/apt/sources.list.d/docker.list: 没有那个文件或目录
#此处说明没有这个文件,则需要自己创建
sulei@sulei:~$  cd /etc/apt/sources.list.d/
sudo touch docker.list
sulei@sulei:/etc/apt/sources.list.d$ cat docker.list
deb https://apt.dockerproject.org/repo ubuntu-precise main




deb https://apt.dockerproject.org/repo ubuntu-precise main


5.更新`sudo apt-get update`
6.丢弃原油的软件包`sudo apt-get purge lxc-docker`
7.验证APT:`apt-cache policy docker-engine`
8.推荐安装`sudo apt-get install linux-image-extra-$(uname -r)`


sulei@sulei:/etc/apt/sources.list.d$ sudo apt-get install linux-image-extra-$(uname -r)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
linux-image-extra-4.4.0-78-generic 已经是最新版 (4.4.0-78.99)。
linux-image-extra-4.4.0-78-generic 已设置为手动安装。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 359 个软件包未被升级。


9.如果是ubuntu14.04或者16.0需要安装apt-get install apparmor


sulei@sulei:/etc/apt/sources.list.d$ sudo apt-get install apparmor
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
apparmor 已经是最新版 (2.10.95-0ubuntu2.6)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 359 个软件包未被升级。


10.安装docker`sulei@sulei:~$ sudo apt-get install docker-engine`
11.启动docker服务


sulei@sulei:~$ sudo service docker start


12.验证docker是否正确


sulei@sulei:~$ sudo docker run hello-world
此处的hello-world需要下载测试镜像
sulei@sulei:~$ ps -Af
sulei@sulei:~$ ps -Af | grep docker
root     12986     1  0 10:38 ?        00:00:02 /usr/bin/dockerd -H fd://
root     13010 12986  0 10:38 ?        00:00:01 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
sulei    14545  9327  0 10:54 pts/1    00:00:00 grep --color=auto docker

sulei@sulei:~$ which docker
/usr/bin/docker

sulei@sulei:~$ sudo 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.
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/


13.配置docker开机自启




14.升级docker


sudo apt-get upgrade docker-engine


15.卸载docker,同时需要删除配置文件


sudo apt-get purge docker-engine


官网的ubuntu的下载的版本

https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#uninstall-old-versions


三.基本的使用命令

查看运行的容器

sulei@sulei:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES
e42060d4b310        hello-world         "/hello"            About a minute ago   Exited (0) About a minute ago                       goofy_carson
dd7ae3703bc9        hello-world         "/hello"            11 hours ago         Exited (0) 11 hours ago                             awesome_mirzakhani
68635209c73e        hello-world         "/hello"            12 hours ago         Exited (0) 12 hours ago                             focused_swanson


docker命令的解释



docker run command

查找并运行指定的镜像

https://hub.docker.com申请Docker的ID

运行镜像

sulei@sulei:~$ sudo docker run docker/whalesay cowsay boo




5. 查看本地镜像

sudo docker images
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  docker