教程 - 部署基于 Docker 的服务

部署基于 Docker 的服务

创建自定义 Docker 镜像

  1. 创建名为 的文件。. 将以下标记粘贴到 index.html 并保存:

  2. 创建名为 的文件。Dockerfile. 将以下 Docker 命令粘贴到其中,并保存:

    1. FROM nginx:1.9
    2. COPY index.html /usr/share/nginx/html/index.html
  3. 构建 Docker 镜像,其中 <username> 是您的 Docker Hub 用户名:

    1. docker build -t <username>/simple-docker .

    输出应类似于:

  4. 登录到 Docker Hub:

      1. docker push <username>/simple-docker

      输出应类似于:

    创建 Docker 应用程序并部署到 DC/OS

    1. 使用以下内容创建 Marathon 应用定义,并另存为 hello-nginx.json. 在 image 字段中,将 <username> 替换为您的 Docker Hub 用户名。在 字段中,根据您偏好的[容器化工具运行时]MESOS 指定 DOCKER 或 (/mesosphere/dcos/cn/2.1/deploying-services/containerizers/) 此文件指定了一个名为 hello-nginx 的简单 Marathon 应用程序,该应用程序在公共节点上运行自身的一个实例。

      1. {
      2. "id": "hello-nginx",
      3. "container": {
      4. "type": "[MESOS | DOCKER]",
      5. "docker": {
      6. "image": "<username>/simple-docker"
      7. },
      8. "portMappings": [
      9. { "hostPort": 80, "containerPort": 80, "protocol": "tcp" }
      10. },
      11. "networks": [
      12. {
      13. }
      14. ],
      15. "acceptedResourceRoles": ["slave_public"],
      16. "instances": 1,
      17. "cpus": 0.1,
      18. "mem": 64
      19. }
    1. 使用 DC/OS 命令将 hello-nginx 应用程序添加到 Marathon:

      如果添加成功,则没有输出。

    2. 如果您选择了 MESOS 运行时间,在您确认添加了该应用程序时,您将看到以下内容:

      1. 在 CloudFormation 中,勾选堆栈旁边的复选框。
      2. 单击 Resources 选项卡。
      3. 搜索 PublicSlavEloadBalancer
      4. 单击 Physical ID(物理 ID)列中的链接。
      5. 按照 中的说明进行操作。

    了解更多

    了解如何使用 [Marathon-LB] 在公共节点上对应用程序进行负载均衡。(/mesosphere/dcos/cn/services/marathon-lb/latest/mlb-basic-tutorial/).