Docker容器初体验

Docker容器初体验_第1张图片
docker.png

1. What is Docker?

Docker容器初体验_第2张图片
Docker-Build_Ship_and_Run_Any_App_Anywhere.png

Wikipedia 定义:
Docker is a software technology providing containers, promoted by the company Docker, Inc. Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux. (Docker 是提供容器的软件技术,在 Linux 上提供了操作系统级虚拟化的额外层次抽象和自动化。)

Docker is an open source project to pack, ship, and run any application as a lightweight container. (Docker 是一个开源项目,用于将任何应用程序作为轻型容器进行打包,运输和运行。)

官方定义:
Docker is the world’s leading software containerization platform. (Docker 是软件集装箱化/容器化平台)

Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. (Docker 是解决跨混合云的应用程序的唯一容器平台提供商)

Docker 特性

  • agility-敏捷:13倍加速软件开发和部署,并立即响应客户需求
  • portability-可移植性:消除“在我这里可以正常运行啊!”问题,一次打包随处运行;通过内部和云环境获得独立性
  • security-安全:通过内置的安全功能和配置,在整个生命周期内提供更安全的应用程序
  • cost savings-节约成本:优化基础设施资源的使用和简化操作,节省50%总成本

MODERN APP PLATFORM - 现代APP平台

The Docker platform is the only container platform to build, secure and manage the widest array of applications from development to production both on premises and in the cloud. (Docker 平台是唯一的容器平台,用于构建、保护和管理应用程序,从开发到生产,在内部和云中)

Docker 平台特性

  • Simplicity-简单:Docker 为应用程序创建和编排提供强大的工具
  • Openness-透明度:采用开源技术和模块化设计,可以轻松集成到现有的环境中
  • Independence-独立:Docker 在开发人员和 IT 之间以及应用程序和基础设施之间建立了分离关键点,以解锁创新

Docker 平台设计理念

  • DEVS:Docker 使开发人员更自由,更具创造力,更快地运送更多的软件
  • OPS:通过跨所有容器化的应用程序和服务的通用控制平台获得可视性,管理和安全性
  • ECOSYSTEM-生态系统:Docker 是一个开放和可扩展的平台,可轻松集成到现有环境中,促进全球科技,商业合作伙伴的充满活力的生态系统

参考

  • Docker (software) - Wikipedia
  • What is Docker Container – An Introduction
  • What is Docker

2. 安装并运行 Docker

在 Mac 上安装 Docker,见 Install Docker for Mac

一、下载并安装 Docker.dmg
二、运行 Docker

Docker容器初体验_第3张图片
docker-app-menu.png

Where to go next

  • Getting started provides an overview of Docker for Mac, basic Docker command examples, how to get help or give feedback, and links to all topics in the Docker for Mac guide.
  • Troubleshooting describes common problems, workarounds, how to run and submit diagnostics, and submit issues.
  • FAQs provides answers to frequently asked questions/为常见问题提供答案.
  • Release Notes lists component updates, new features, and improvements associated with Stable and Edge releases/罗列组件更新,新功能和改进.
  • Get Started with Docker provides a general Docker tutorial/提供一个通用的Docker教程.

3. 玩转 Docker

跟着 Get started with Docker 开始使用 Docker。

Docker容器初体验_第4张图片
engine-components-flow.png

3.1 检查 Docker Engine/引擎, Compose/组装, and Machine/机器的版本

➜  ~ docker --version
Docker version 17.09.0-ce, build afdb6d4
➜  ~ docker-compose --version
docker-compose version 1.16.1, build 6d1ac21
➜  ~ docker-machine --version
docker-machine version 0.12.2, build 9371605

3.2 探讨应用和运行示例

3.2.1 运行一些Docker命令验证Docker是否按预期工作

➜  ~ docker version
......
# Docker daemon 未启动
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
➜  ~ docker version
# Docker 客户端
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:09 2017
 OS/Arch:      darwin/amd64

# Docker 服务端版本,API版本,Go版本
Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:45:38 2017
 OS/Arch:      linux/amd64
 Experimental: true
➜  ~ docker ps
# 无容器运行中
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
➜  ~ 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. (Docker客户端联系Docker服务端守护进程)
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Docker守护进程从Docker Hub拉取“hello-world”镜像)
 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. (Docker守护进程从该镜像创建一个新的容器,该容器运行可执行文件,生成当前正在读取的输出)
 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. (Docker守护进程将输出的流式内容传输到Docker客户端,Docker客户端将其发送到您的终端)

Share images, automate workflows, and more with a free Docker ID/通过免费的Docker ID共享镜像,自动化工作流程等:
 https://cloud.docker.com/

For more examples and ideas, visit/想了解更多示例和想法,请访问:
 https://docs.docker.com/engine/userguide/
  • Docker Hub: Dev-test pipeline automation, 100,000+ free apps, public and private registries
  • Docker Cloud: The official cloud service for continuously delivering Docker applications
  • Docker User Guides

3.2.2 启动容器化的Web服务器

➜  ~ docker run -d -p 80:80 --name webserver nginx
122424b8077b791b42b31898eef3b77aa054a994b663fc832d5e90de430ac65a
# 启动用户态代理时出错:80端口已使用
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (0f305bfd15dcf2914f7bf2c815ed94412706f85e3a2d9d2e83ec7423d58a1726): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
➜  ~ docker run -d -p 80:80 --name webserver nginx
# 冲突:容器名称"/webserver"已使用,您必须删除(或重命名)该容器才能重用该名称
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container "122424b8077b791b42b31898eef3b77aa054a994b663fc832d5e90de430ac65a". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
➜  ~ docker rm webserver
webserver

Nginx启动正常:Networking features in Docker for Mac

➜  ~ docker run -d -p 8080:80 --name webserver nginx
# 容器ID
61a674b351579ccc527f13f679ace017147789ae667dc5ff0caa275add1e898f

在Web浏览器中,转到 http://localhost:8080/ 打开主页。

3.2.3 查看容器详细信息

➜  ~ docker ps
# 容器ID,镜像名称,运行命令,创建时间,运行状态,端口映射,容器名称
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp   webserver

3.2.4 停止或移除容器或镜像

停止或启动容器

➜  ~ docker stop webserver
webserver
➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
➜  ~ docker start webserver
webserver
➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up 1 second         0.0.0.0:8080->80/tcp   webserver
➜  ~ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up 8 seconds              0.0.0.0:8080->80/tcp   webserver
cecc48eb752e        hello-world         "/hello"                 2 hours ago         Exited (0) 2 hours ago                           pedantic_almeida

停止并移除运行中的容器

➜  ~ docker rm -f webserver
webserver

列出本地镜像

➜  ~ docker images
# 仓库,标签,镜像ID,创建时间,镜像大小
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              c59f17fe53b0        6 days ago          108MB
alpine              latest              37eec16f1872        8 days ago          3.97MB
hello-world         latest              05a3bd381fc2        7 weeks ago         1.84kB

首选项

包括 General,File sharing,Advanced,HTTP proxy settings,Docker Daemon


Docker容器初体验_第5张图片
Preferences.png

添加TLS证书

安装bash完成

提供反馈并获得帮助

Docker Store

Docker store is a component of the next-generation Docker Hub, and the best place to find compliant, trusted commercial and free software distributed as Docker Images.

The Docker Store - Find Trusted and Enterprise Ready Containers, Plugins, and Docker Editions/查找可信和企业就绪的容器、插件和Docker版本

Docker容器初体验_第6张图片
docker-store.png

Docker Cloud

Docker Cloud - Build, Ship and Run any App, Anywhere
The official cloud service for continuously delivering Docker applications.

  • Continuous integration (CI) for Docker/Docker持续集成
  • Fully-managed Docker Registry Service/完全托管的Docker注册服务
  • Provision & manage Swarms/配置和管理集群
Docker容器初体验_第7张图片
docker-cloud.png

Where to go next

  • Try out the walkthrough/尝试演练 at Get Started.
  • Dig in deeper with Docker Labs example walkthroughs and source code/深入挖掘Docker Labs的示例演练和源代码.
  • For a summary of Docker command line interface (CLI) commands, see Docker CLI Reference Guide/有关Docker命令行界面(CLI)命令的摘要,见Docker命令行界面参考指南.
  • Check out the blog post/看看博客文章 Introducing Docker 1.13.0.

祝玩得开心!ˇˍˇ
云舒,2017.11.2,杭州

你可能感兴趣的:(Docker容器初体验)