Skip to content

Commit bf6c8d5

Browse files
authored
Merge pull request #115402 from DCtheGeek/dmc-batch-ghi29449
Fixes MicrosoftDocs/azure-docs#29449 - Updating C# snippets
2 parents 6d92945 + c239593 commit bf6c8d5

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

articles/batch/batch-docker-container-workloads.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
title: Container workloads
33
description: Learn how to run and scale apps from container images on Azure Batch. Create a pool of compute nodes that support running container tasks.
44
ms.topic: article
5-
ms.date: 03/02/2020
5+
ms.date: 05/20/2020
66
ms.custom: seodec18
7-
87
---
9-
108
# Run container applications on Azure Batch
119

1210
Azure Batch lets you run and scale large numbers of batch computing jobs on Azure. Batch tasks can run directly on virtual machines (nodes) in a Batch pool, but you can also set up a Batch pool to run tasks in Docker-compatible containers on the nodes. This article shows you how to create a pool of compute nodes that support running container tasks, and then run container tasks on the pool.
@@ -155,32 +153,40 @@ new_pool = batch.models.PoolAddParameter(
155153
The following C# example assumes that you want to prefetch a TensorFlow image from [Docker Hub](https://hub.docker.com). This example includes a start task that runs in the VM host on the pool nodes. You might run a start task in the host, for example, to mount a file server that can be accessed from the containers.
156154

157155
```csharp
158-
159156
ImageReference imageReference = new ImageReference(
160157
publisher: "microsoft-azure-batch",
161158
offer: "ubuntu-server-container",
162159
sku: "16-04-lts",
163160
version: "latest");
164161

162+
ContainerRegistry containerRegistry = new ContainerRegistry(
163+
registryServer: "https://hub.docker.com",
164+
userName: "UserName",
165+
password: "YourPassword"
166+
);
167+
165168
// Specify container configuration, prefetching Docker images
166-
ContainerConfiguration containerConfig = new ContainerConfiguration(
167-
containerImageNames: new List<string> { "tensorflow/tensorflow:latest-gpu" } );
169+
ContainerConfiguration containerConfig = new ContainerConfiguration();
170+
containerConfig.ContainerImageNames = new List<string> { "tensorflow/tensorflow:latest-gpu" };
171+
containerConfig.ContainerRegistries = new List<ContainerRegistry> { containerRegistry };
168172

169173
// VM configuration
170174
VirtualMachineConfiguration virtualMachineConfiguration = new VirtualMachineConfiguration(
171175
imageReference: imageReference,
172-
containerConfiguration: containerConfig,
173176
nodeAgentSkuId: "batch.node.ubuntu 16.04");
177+
virtualMachineConfiguration.ContainerConfiguration = containerConfig;
174178

175179
// Set a native host command line start task
176-
StartTask startTaskNative = new StartTask( CommandLine: "<native-host-command-line>" );
180+
StartTask startTaskContainer = new StartTask( commandLine: "<native-host-command-line>" );
177181

178182
// Create pool
179183
CloudPool pool = batchClient.PoolOperations.CreatePool(
180184
poolId: poolId,
181-
targetDedicatedComputeNodes: 4,
182185
virtualMachineSize: "Standard_NC6",
183-
virtualMachineConfiguration: virtualMachineConfiguration, startTaskContainer);
186+
virtualMachineConfiguration: virtualMachineConfiguration);
187+
188+
// Start the task in the pool
189+
pool.StartTask = startTaskContainer;
184190
...
185191
```
186192

@@ -191,22 +197,22 @@ You can also prefetch container images by authenticating to a private container
191197

192198
```csharp
193199
// Specify a container registry
194-
ContainerRegistry containerRegistry = new ContainerRegistry (
195-
registryServer: "myContainerRegistry.azurecr.io",
196-
username: "myUserName",
200+
ContainerRegistry containerRegistry = new ContainerRegistry(
201+
registryServer: "myContainerRegistry.azurecr.io",
202+
userName: "myUserName",
197203
password: "myPassword");
198204

199205
// Create container configuration, prefetching Docker images from the container registry
200-
ContainerConfiguration containerConfig = new ContainerConfiguration(
201-
containerImageNames: new List<string> {
202-
"myContainerRegistry.azurecr.io/tensorflow/tensorflow:latest-gpu" },
203-
containerRegistries: new List<ContainerRegistry> { containerRegistry } );
206+
ContainerConfiguration containerConfig = new ContainerConfiguration();
207+
containerConfig.ContainerImageNames = new List<string> {
208+
"myContainerRegistry.azurecr.io/tensorflow/tensorflow:latest-gpu" };
209+
containerConfig.ContainerRegistries = new List<ContainerRegistry> { containerRegistry } );
204210

205211
// VM configuration
206212
VirtualMachineConfiguration virtualMachineConfiguration = new VirtualMachineConfiguration(
207213
imageReference: imageReference,
208-
containerConfiguration: containerConfig,
209214
nodeAgentSkuId: "batch.node.ubuntu 16.04");
215+
virtualMachineConfiguration.ContainerConfiguration = containerConfig;
210216

211217
// Create pool
212218
CloudPool pool = batchClient.PoolOperations.CreatePool(
@@ -281,7 +287,6 @@ The following C# example shows basic container settings for a cloud task:
281287

282288
```csharp
283289
// Simple container task command
284-
285290
string cmdLine = "c:\\app\\myApp.exe";
286291

287292
TaskContainerSettings cmdContainerSettings = new TaskContainerSettings (
@@ -291,11 +296,10 @@ TaskContainerSettings cmdContainerSettings = new TaskContainerSettings (
291296

292297
CloudTask containerTask = new CloudTask (
293298
id: "Task1",
294-
containerSettings: cmdContainerSettings,
295-
commandLine: cmdLine);
299+
commandline: cmdLine);
300+
containerTask.ContainerSettings = cmdContainerSettings;
296301
```
297302

298-
299303
## Next steps
300304

301305
* Also see the [Batch Shipyard](https://github.com/Azure/batch-shipyard) toolkit for easy deployment of container workloads on Azure Batch through [Shipyard recipes](https://github.com/Azure/batch-shipyard/tree/master/recipes).

0 commit comments

Comments
 (0)