Docker

Docker容器初体验

2017-11-02  本文已影响74人  简放视野
docker.png

1. What is Docker?

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 特性

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 平台特性

Docker 平台设计理念

参考

2. 安装并运行 Docker

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

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

docker-app-menu.png

Where to go next

3. 玩转 Docker

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

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/

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


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-store.png

Docker Cloud

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

docker-cloud.png

Where to go next


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

上一篇下一篇

猜你喜欢

热点阅读