|
| 1 | +--- |
| 2 | +title: Install and run containers - Translator Text |
| 3 | +titleSuffix: Azure Cognitive Services |
| 4 | +description: How to download, install, and run containers for Translator Text Analytics in this walkthrough tutorial. |
| 5 | +services: cognitive-services |
| 6 | +author: IEvangelist |
| 7 | +manager: nitinme |
| 8 | +ms.service: cognitive-services |
| 9 | +ms.subservice: translator-text |
| 10 | +ms.topic: conceptual |
| 11 | +ms.date: 11/04/2019 |
| 12 | +ms.author: dapine |
| 13 | +--- |
| 14 | + |
| 15 | +# Install and run Translator Text containers |
| 16 | + |
| 17 | +<!-- |
| 18 | + ACOM forward link: |
| 19 | + https://docs.microsoft.com/azure/cognitive-services/translator/howto-install-containers |
| 20 | +--> |
| 21 | + |
| 22 | +Containers enable you to run the Translator Text APIs in your own environment and are great for specific security and data governance requirements. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +You must meet the following prerequisites before using Translator Text containers: |
| 27 | + |
| 28 | +|Required|Purpose| |
| 29 | +|--|--| |
| 30 | +|Docker Engine| You need the Docker Engine installed on a [host computer](#the-host-computer). Docker provides packages that configure the Docker environment on [macOS](https://docs.docker.com/docker-for-mac/), [Windows](https://docs.docker.com/docker-for-windows/), and [Linux](https://docs.docker.com/engine/installation/#supported-platforms). For a primer on Docker and container basics, see the [Docker overview](https://docs.docker.com/engine/docker-overview/).<br><br> **On Windows**, Docker must also be configured to support Linux containers.<br><br>| |
| 31 | +|Familiarity with Docker | You should have a basic understanding of Docker concepts, like registries, repositories, containers, and container images, as well as knowledge of basic `docker` commands.| |
| 32 | + |
| 33 | +## Request access to the container registry |
| 34 | + |
| 35 | +You must first complete and submit the [Cognitive Translator Text Containers Request form](https://aka.ms/translatorcontainerform) to request access to the container. |
| 36 | + |
| 37 | +[!INCLUDE [Request access to the container registry](../../../includes/cognitive-services-containers-request-access-only.md)] |
| 38 | + |
| 39 | +[!INCLUDE [Authenticate to the container registry](../../../includes/cognitive-services-containers-access-registry.md)] |
| 40 | + |
| 41 | +### The host computer |
| 42 | + |
| 43 | +The host is an x64-based computer with a Linux OS that runs the Docker container. It can be a computer on your premises or a Docker hosting service in Azure, such as: |
| 44 | + |
| 45 | +* Azure Kubernetes Service. |
| 46 | +* Azure Container Instances. |
| 47 | +* A [Kubernetes](https://kubernetes.io/) cluster deployed to Azure Stack. |
| 48 | + |
| 49 | +### Container requirements and recommendations |
| 50 | + |
| 51 | +The following table describes the minimum and recommended CPU cores, at least 2.6 gigahertz (GHz) or faster, and memory, in gigabytes (GB), to allocate for each Translator Text container. |
| 52 | + |
| 53 | +| Container | Minimum | Language pair | |
| 54 | +|-----------|---------|---------------| |
| 55 | +| Translator Text | 4 core, 4 GB memory | 4 | |
| 56 | + |
| 57 | +For every language pair, it's recommended to have 1 GB of memory. By default, the Translator Text container has 3 or 4 language pairs, depending on the `<image-tag>` you're running. See [supported languages and translation](#supported-languages-and-translation) for the details. The core and memory correspond to the `--cpus` and `--memory` settings, which are used as part of the `docker run` command. |
| 58 | + |
| 59 | +## Get the container image with `docker pull` |
| 60 | + |
| 61 | +Container images for Translator Text are available in the following container repository. The table also maps the container image tags and their corresponding supported languages. |
| 62 | + |
| 63 | +| Container | Image tag | Languages supported | |
| 64 | +|-----------|-----------|---------------------| |
| 65 | +| `containerpreview.azurecr.io/microsoft/cognitive-services-translator-text` | `ar_de_en_ru_zh_1.0.0` | `ar-SA`, `zh-CN`, `de-DE`, and `ru-RU` | |
| 66 | +| `containerpreview.azurecr.io/microsoft/cognitive-services-translator-text` | `de_en_es_fr_1.0.0` | `de-DE`, `fr-FR`, and `es-ES` | |
| 67 | + |
| 68 | +[!INCLUDE [Tip for using docker list](../../../includes/cognitive-services-containers-docker-list-tip.md)] |
| 69 | + |
| 70 | +### Docker pull for the Translator Text container |
| 71 | + |
| 72 | +To perform the [`docker pull`](https://docs.docker.com/engine/reference/commandline/pull/) command, you first need access to the container registry. From the Azure CLI you can login to the Azure Container Registry using the [`az acr login`](https://docs.microsoft.com/cli/azure/acr?view=azure-cli-latest#az-acr-login) command. |
| 73 | + |
| 74 | +```azureinteractive |
| 75 | +az acr login --name containerpreview.azurecr.io |
| 76 | +``` |
| 77 | + |
| 78 | +This command will authenticate your current user with the corresponding Azure Container Registry. Now, you're free to execute the `docker pull` command. |
| 79 | + |
| 80 | +> [!NOTE] |
| 81 | +> Depending on what language support you need, provide the corresponding `<image-tag>`. |
| 82 | +
|
| 83 | +```Docker |
| 84 | +docker pull containerpreview.azurecr.io/microsoft/cognitive-services-translator-text:<image-tag> |
| 85 | +``` |
| 86 | + |
| 87 | +## How to use the container |
| 88 | + |
| 89 | +Once the container is on the [host computer](#the-host-computer), use the following process to work with the container. |
| 90 | + |
| 91 | +1. [Run the container](#run-the-container-with-docker-run). More [examples](translator-text-container-config.md#example-docker-run-commands) of the `docker run` command are available. |
| 92 | +1. [Query the container's translate endpoint](#query-the-containers-translate-endpoint). |
| 93 | + |
| 94 | +## Run the container with `docker run` |
| 95 | + |
| 96 | +Use the [docker run](https://docs.docker.com/engine/reference/commandline/run/) command to run any of the three containers. [Examples](translator-text-container-config.md#example-docker-run-commands) of the `docker run` command are available. |
| 97 | + |
| 98 | +### Run container example of docker run command |
| 99 | + |
| 100 | +```Docker |
| 101 | +docker run --rm -it -p 5000:80 --memory 4g --cpus 4 \ |
| 102 | +containerpreview.azurecr.io/microsoft/cognitive-services-translator-text:ar_de_en_ru_zh_1.0.0 \ |
| 103 | +Eula=accept |
| 104 | +``` |
| 105 | + |
| 106 | +This command: |
| 107 | + |
| 108 | +* Runs a Translator Text container from the container image |
| 109 | +* Allocates 4 CPU core and 4 gigabytes (GB) of memory |
| 110 | +* Exposes TCP port 5000 and allocates a pseudo-TTY for the container |
| 111 | +* Accepts the end user agreement (EULA) |
| 112 | +* Automatically removes the container after it exits. The container image is still available on the host computer |
| 113 | + |
| 114 | +### How to collect docker logs |
| 115 | + |
| 116 | +For troubleshooting purposes, it may be useful to view the docker logs from the container's execution. First, execute the [docker ps](https://docs.docker.com/engine/reference/commandline/ps/) command with the formatting flag to limit the details displayed for all the containers. |
| 117 | + |
| 118 | +```Docker |
| 119 | +docker ps -a --format "table {{.ID}}\t{{.Image}}\t{{.Status}}" |
| 120 | +
|
| 121 | +CONTAINER ID IMAGE STATUS |
| 122 | +ed6f115697f3 containerpreview.azurecr.io/microsoft/cognitive-services-translator-text Up 4 minutes |
| 123 | +``` |
| 124 | + |
| 125 | +Then, run the [docker logs](https://docs.docker.com/engine/reference/commandline/logs/) command with the `<Container ID>` for the corresponding container in question to view its logs. |
| 126 | + |
| 127 | +```Docker |
| 128 | +docker logs <Container ID> --timestamps --since=4h | grep Error |
| 129 | +``` |
| 130 | + |
| 131 | +The docker logs command above will collect the "Error" logs for the last four hours. |
| 132 | + |
| 133 | +## Supported languages and translation |
| 134 | + |
| 135 | +The `POST /translate` method supports the following languages conversions, moving from *English* to a target language and vice versa. Please note that while you can go to and from English with one of the languages listed, you *cannot* go from one *non-English* language to another *non-English* language. |
| 136 | + |
| 137 | +> [!NOTE] |
| 138 | +> For optimal quality, consumers should only send one sentence per request. |
| 139 | +
|
| 140 | +| Language conversion | Language ISO conversion | Image tags | |
| 141 | +|--|--|:--| |
| 142 | +| English :left_right_arrow: Chinese | `en-US` :left_right_arrow: `zh-CN` | `ar_de_en_ru_zh_1.0.0` | |
| 143 | +| English :left_right_arrow: Russian | `en-US` :left_right_arrow: `ru-RU` | `ar_de_en_ru_zh_1.0.0` | |
| 144 | +| English :left_right_arrow: Arabic | `en-US` :left_right_arrow: `ar-SA` | `ar_de_en_ru_zh_1.0.0` | |
| 145 | +| English :left_right_arrow: German | `en-US` :left_right_arrow: `de-DE` | `ar_de_en_ru_zh_1.0.0` and `de_en_es_fr_1.0.0` | |
| 146 | +| English :left_right_arrow: Spanish | `en-US` :left_right_arrow: `es-ES` | `de_en_es_fr_1.0.0` | |
| 147 | +| English :left_right_arrow: French | `en-US` :left_right_arrow: `fr-FR` | `de_en_es_fr_1.0.0` | |
| 148 | + |
| 149 | +> [!IMPORTANT] |
| 150 | +> The `Eula` must be specified to run the container; otherwise, the container won't start. |
| 151 | +
|
| 152 | +## Query the container's translate endpoint |
| 153 | + |
| 154 | +The container provides a REST-based translate endpoint API. Several example usages of this endpoint are as follows: |
| 155 | + |
| 156 | +# [cURL](#tab/curl) |
| 157 | + |
| 158 | + |
| 159 | +Execute the following cURL command, from your desired CLI. |
| 160 | + |
| 161 | +```curl |
| 162 | +curl -X POST "http://localhost:5000/translate?api-version=3.0&from=en-US&to=de-DE" |
| 163 | + -H "Content-Type: application/json" -d "[{'Text':'hello, how are you'}]" |
| 164 | +``` |
| 165 | + |
| 166 | +> [!TIP] |
| 167 | +> If you attempt this cURL POST before the container is ready, you'll end up getting a "Service is temporarily unavailable" response. Simply wait until the container is ready, then try again. |
| 168 | +
|
| 169 | +The following output will be printed to the console. |
| 170 | + |
| 171 | +```console |
| 172 | +"translations": [ |
| 173 | + { |
| 174 | + "text": "hallo, wie geht es dir", |
| 175 | + "to": "de-DE" |
| 176 | + } |
| 177 | +] |
| 178 | +``` |
| 179 | + |
| 180 | +# [Swagger](#tab/Swagger) |
| 181 | + |
| 182 | +Navigate to the swagger page, http://localhost:5000/swagger/index.html |
| 183 | + |
| 184 | +1. Select **POST /translate** |
| 185 | +1. Select **Try it out** |
| 186 | +1. Enter the **From** parameter as `en-US` |
| 187 | +1. Enter the **To** parameter as `de-DE` |
| 188 | +1. Enter the **api-version** parameter as `3.0` |
| 189 | +1. Under **texts**, replace `string` with the following JSON |
| 190 | + ```json |
| 191 | + [ |
| 192 | + { |
| 193 | + "text": "hello, how are you" |
| 194 | + } |
| 195 | + ] |
| 196 | + ``` |
| 197 | +1. Select **Execute**, the resulting translations are output in the **Response Body**. You should expect something similar to the following: |
| 198 | + ```json |
| 199 | + "translations": [ |
| 200 | + { |
| 201 | + "text": "hallo, wie geht es dir", |
| 202 | + "to": "de-DE" |
| 203 | + } |
| 204 | + ] |
| 205 | + ``` |
| 206 | + |
| 207 | +# [.NET Core](#tab/netcore) |
| 208 | + |
| 209 | +1. Launch Visual Studio, and create a new console application. |
| 210 | +1. Edit the `*.csproj` file to add the `<LangVersion>7.1</LangVersion>` node - this specifies C# 7.1. |
| 211 | +1. Add the [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/) NuGet package, version 11.0.2. |
| 212 | +1. In `Program.cs`, replace all the existing code with the following: |
| 213 | + ```csharp |
| 214 | + using Newtonsoft.Json; |
| 215 | + using System; |
| 216 | + using System.Net.Http; |
| 217 | + using System.Text; |
| 218 | + using System.Threading.Tasks; |
| 219 | + |
| 220 | + namespace TranslateContainer |
| 221 | + { |
| 222 | + class Program |
| 223 | + { |
| 224 | + const string ApiHostEndpoint = "http://localhost:5000"; |
| 225 | + const string TranslateApi = "/translate?api-version=3.0&from=en-US&to=de-DE"; |
| 226 | + |
| 227 | + static async Task Main(string[] args) |
| 228 | + { |
| 229 | + var textToTranslate = "hello, how are you"; |
| 230 | + var result = await TranslateTextAsync(textToTranslate); |
| 231 | + |
| 232 | + Console.WriteLine(result); |
| 233 | + Console.ReadLine(); |
| 234 | + } |
| 235 | + |
| 236 | + static async Task<string> TranslateTextAsync(string textToTranslate) |
| 237 | + { |
| 238 | + var body = new object[] { new { Text = textToTranslate } }; |
| 239 | + var requestBody = JsonConvert.SerializeObject(body); |
| 240 | + |
| 241 | + var client = new HttpClient(); |
| 242 | + using (var request = |
| 243 | + new HttpRequestMessage |
| 244 | + { |
| 245 | + Method = HttpMethod.Post, |
| 246 | + RequestUri = new Uri($"{ApiHostEndpoint}{TranslateApi}"), |
| 247 | + Content = new StringContent(requestBody, Encoding.UTF8, "application/json") |
| 248 | + }) |
| 249 | + { |
| 250 | + // Send the request and await a response. |
| 251 | + var response = await client.SendAsync(request); |
| 252 | + |
| 253 | + return await response.Content.ReadAsStringAsync(); |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + } |
| 258 | + ``` |
| 259 | +1. Press **F5** to run the program. |
| 260 | +1. The following output will be printed to the console. |
| 261 | + ```console |
| 262 | + "translations": [ |
| 263 | + { |
| 264 | + "text": "hallo, wie geht es dir", |
| 265 | + "to": "de-DE" |
| 266 | + } |
| 267 | + ] |
| 268 | + ``` |
| 269 | + |
| 270 | +*** |
| 271 | + |
| 272 | +[!INCLUDE [Container's API documentation](../../../includes/cognitive-services-containers-api-documentation.md)] |
| 273 | + |
| 274 | +## Stop the container |
| 275 | + |
| 276 | +[!INCLUDE [How to stop the container](../../../includes/cognitive-services-containers-stop.md)] |
| 277 | + |
| 278 | +## Troubleshooting |
| 279 | + |
| 280 | +If you run the container with an output [mount](translator-text-container-config.md#mount-settings) and logging enabled, the container generates log files that are helpful to troubleshoot issues that happen while starting or running the container. |
| 281 | + |
| 282 | +<!--blogs/samples/video course --> |
| 283 | + |
| 284 | +[!INCLUDE [Discoverability of more container information](../../../includes/cognitive-services-containers-discoverability.md)] |
| 285 | + |
| 286 | +## Summary |
| 287 | + |
| 288 | +In this article, you learned concepts and workflow for downloading, installing, and running Translator Text containers. In summary: |
| 289 | + |
| 290 | +* Translator Text provides multiple Linux containers for Docker, encapsulating various language pairs. |
| 291 | +* Container images are downloaded from the "Container Preview" registry. |
| 292 | +* Container images run in Docker. |
| 293 | +* You can use either the REST API or SDK to call operations in Translator Text containers by specifying the host URI of the container. |
| 294 | + |
| 295 | +## Next steps |
| 296 | + |
| 297 | +* Review [Configure containers](translator-text-container-config.md) for configuration settings |
| 298 | +* Refer to [container frequently asked questions (FAQ)](../containers/container-faq.md) to resolve issues related to functionality. |
0 commit comments