1. 程式人生 > >原 docker官網手冊譯part 3

原 docker官網手冊譯part 3

Introduction

In part 3, we scale our application and enable load-balancing. To do this, we must go one level up in the hierarchy of a distributed application: the service.

part3,我們將拓展應用,支援負載均衡。做到這點,我們必須使用更上級分散式應用層:the service

About services

In a distributed application, different pieces of the app are called “services.” For example, if you imagine a video sharing site, it probably includes a service for storing application data in a database, a service for video transcoding in the background after a user uploads something, a service for the front-end, and so on.

分散式應用程式中,不同的app部分稱為services。如,你設想一個視訊分享網站,它可能包含資料儲存服務,使用者上傳視訊轉碼服務,前端服務等等。

Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. Scaling a service changes the number of container instances running that piece of software, assigning more computing resources to the service in the process.

Services 其實是生產中containers。一個service只執行一個映象,但定義了映象的執行方式--埠的使用,服務需要的container副本數,等等。拓展一個服務只是改變執行軟體container例項的個數,程序中指定更多的計算資源指向服務。

Luckily it’s very easy to define, run, and scale services with the Docker platform -- just write a docker-compose.yml file.

幸運的是通過Docker平臺可以非常簡單的定義,執行,拓展服務--只需定義一個docker-compose.yml檔案。

Your first docker-compose.yml file

docker-compose.yml file is a YAML file that defines how Docker containers should behave in production.

docker-compose.yml是YAML 檔案定義了Docker containers在生產中的行為。

Save this file as docker-compose.yml wherever you want. Be sure you have pushed the image you created in Part 2 to a registry, and update this .yml by replacingusername/repo:tag with your image details.

儲存docker-compose到任意位置。確保你已經上傳了part2中映象。用你映象詳情替換.yml中username/repo:tag程式碼。

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    image: username/repo:tag
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "4000:80"
    networks:
      - webnet
networks:
  webnet: