目录
- 本地搭建Docker环境
本地搭建Docker环境
一、What is Docker
1 Modernize your applications, accelerate innovation Securely build, share and run modern applications anywhere使您的应用程序现代化,加速创新安全地在任何地方构建、共享和运行现代应用程序
1 Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.Docker是开发人员和系统管理员使用容器开发、部署和运行应用程序的平台。使用Linux容器部署应用程序称为容器化。容器不是新的,但它们用于轻松部署应用程序的用途。
1. 如何理解容器化
①远古时代

问题:成本高、部署慢、浪费资源、硬件限制、不利于迁移扩展
②虚拟化时代

优点:相对利用好资源、相对容易扩展等。
缺点:虚拟机太重了,一上来占用较多物理资源,移植性差,资源利用率低等。
③容器时代

2. Docker应用场景
www.docker.com —>Solutions
1 | 有助于Microservices的落地和部署 |
二、What is Image and Container?
1. What is Image?
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed
to run an application: code, runtime, system tools, system libraries and settings.Docker容器映像是一个轻量级的、独立的、可执行的软件包,包含运行应用程序所需的一切:代码、运行时、系统工具、系统库和设置。
2. What is Container?
A container is a standard unit of software that packages up code and all its dependencies so the application runs
quickly and reliably from one computing environment to another.容器是一个标准的软件单元,它将代码及其所有依赖项打包,以便应用程序从一个计算环境快速可靠地运行到另一个计算环境。
3. Relation between image and container
Container images become containers at runtime and in the case of Docker containers- images become containers when they
run on Docker Engine.容器映像在运行时成为容器,在Docker容器的情况下,映像在Docker引擎上运行时成为容器。
4. View from Docs
A container is launched by running an image. An image is an executable package that includes everything needed to run
an application–the code, a runtime, libraries, environment variables, and configuration files.A container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with
state, or a user process). You can see a list of your running containers with the command, docker ps, just as you
would
in Linux.通过运行图像启动容器映像是一个可执行包,包含运行应用程序所需的所有内容—代码、运行时、库、环境变量和配置文件。
容器是映像的运行时实例——映像在执行时在内存中变成什么(即,具有状态的映像或用户进程)。您可以使用命令docker
ps查看正在运行的容器的列表,就像在linux中一样。
5. Container and virtual machines
A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete
process, taking no more memory than any other executable, making it lightweight.By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources
through a hypervisor. In general, VMs provide an environment with more resources than most applications need.容器在Linux上本机运行,并与其他容器共享主机的内核。它运行一个离散的进程,占用的内存不比任何其他可执行文件多,因此它很轻。
相比之下,虚拟机(vm)运行一个完整的“来宾”操作系统,通过虚拟机监控程序对主机资源进行虚拟访问。一般来说,vm为环境提供的资源比大多数应用程序需要的资源多。

三、 Docker Engine and Architecture
1. Docker Engine
Docker Engine is a client-server application with these major components:
- A server which is a type of long-running program called a daemon process (the
dockerdcommand)
.(一种称为守护进程的长时间运行程序(dockerd命令)的服务器。) - A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.(一个rest
api,它指定程序可以用来与守护进程对话并指示它做什么的接口。) - A command line interface (CLI) client (the
dockercommand).(命令行界面(cli)客户端(“docker”命令))

2. Docker Architecture
Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting
of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same
system,
or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST
API,
over UNIX sockets or a network interface.
Docker使用客户机-服务器架构。Docker客户端与Docker守护进程通信,后者负责构建、运行和分发Docker容器。Docker客户端和守护进程可以在同一个系统上运行,也可以将Docker客户端连接到远程Docker守护进程。Docker客户端和守护进程使用一个rest
api,通过unix套接字或网络接口进行通信。

四、 Install and Experience

1、 在Windows上准备centos7
采用vagrant + virtual box的方式进行环境搭建。
①、 下载安装vagrant
1 | 访问 [Vagrant](https://www.vagrantup.com) 官网 |

②、 下载安装virtual box
1 | 访问 [VirtualBox](https://www.virtualbox.org/) 官网 |
③、 安装centos7
1 | 在本地磁盘中创建frist-docker-centos7文件夹,并进入其中[目录路径不要有中文字符] |
至此,使用vagrant+virtualbox搭建centos7完成,后面可以修改Vagrantfile对虚拟机进行相应的配置。
④、 若想通过ssh客户端连接
1 | 查看centos7的相关信息 |
⑤、 box的打包分发
1 | 退出虚拟机 |
2、 安装Docker
1 | 进入centos7 |
3、 Docker基本体验
1 | 创建tomcat容器 |
4、 解疑
(1)docker pull在哪里拉取的镜像?
默认是在hub.docker.com
(2)docker pull tomcat拉取的版本是?
默认是最新的版本,可以在后面指定版本“:”
(3)简单先说下命令
docker pull 拉取镜像到本地
docker run 根据某个镜像创建容器
-d 让容器在后台运行,起始就是一个进程
–name 给容器指定一个名字
-p 将容器的端口映射到宿主机的端口
docker exec -it 进入到某个容器中并交互式运行