Skip to content

Commit af0b609

Browse files
Merge pull request #277173 from alfpark/alpark/batch
Clarify Batch Docker entrypoint, cmd, workdir effects
2 parents c2044a9 + 54eebd4 commit af0b609

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Container workloads on Azure Batch
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: how-to
5-
ms.date: 05/31/2024
5+
ms.date: 06/04/2024
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp, linux-related-content
88
---
@@ -50,7 +50,7 @@ Keep in mind the following limitations:
5050
- For Windows container workloads, you should choose a multicore VM size for your pool.
5151

5252
> [!IMPORTANT]
53-
> Docker, by default, will create a network bridge with a subnet specification of `172.17.0.0/16`. If you are specifying a
53+
> Docker, by default, creates a network bridge with a subnet specification of `172.17.0.0/16`. If you are specifying a
5454
> [virtual network](batch-virtual-network.md) for your pool, ensure that there are no conflicting IP ranges.
5555
5656
## Supported VM images
@@ -393,15 +393,41 @@ When you run a container task, Batch automatically uses the [docker create](http
393393

394394
As with non-container Batch tasks, you set a command line for a container task. Because Batch automatically creates the container, the command line only specifies the command or commands that run in the container.
395395

396-
If the container image for a Batch task is configured with an [ENTRYPOINT](https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example) script, you can set your command line to either use the default ENTRYPOINT or override it:
397-
398-
- To use the default ENTRYPOINT of the container image, set the task command line to the empty string `""`.
399-
400-
- To override the default ENTRYPOINT, add the `--entrypoint` argument for example: `--entrypoint "/bin/sh - python"`
401-
402-
- If the image doesn't have an ENTRYPOINT, set a command line appropriate for the container, for example, `/app/myapp` or `/bin/sh -c python myscript.py`
403-
404-
Optional [ContainerRunOptions](/dotnet/api/microsoft.azure.batch.taskcontainersettings.containerrunoptions) are other arguments you provide to the `docker create` command that Batch uses to create and run the container. For example, to set a working directory for the container, set the `--workdir <directory>` option. See the [docker create](https://docs.docker.com/engine/reference/commandline/create/) reference for more options.
396+
The following are the default behaviors Batch applies to Docker container tasks:
397+
398+
- Batch will run the container with the specified task commandline as the [CMD](https://docs.docker.com/reference/dockerfile/#cmd).
399+
- Batch won't interfere with the specified [ENTRYPOINT](https://docs.docker.com/reference/dockerfile/#entrypoint) of the container image.
400+
- Batch will override the [WORKDIR](https://docs.docker.com/reference/dockerfile/#workdir) with the [Batch task working directory](batch-compute-node-environment-variables.md).
401+
402+
Ensure that you review the Docker documentation between ENTRYPOINT and CMD so you understand the
403+
interaction effects that can arise when container images have a specified ENTRYPOINT and you also
404+
specify a task commandline.
405+
406+
If you would like to override the container image ENTRYPOINT, you can specify the `--entrypoint <args>`
407+
argument as a containerRunOption. Refer to the optional [ContainerRunOptions](/dotnet/api/microsoft.azure.batch.taskcontainersettings.containerrunoptions)
408+
for arguments that you can provide to the `docker create` command that Batch uses to create and run the
409+
container. For example, to set a working directory for the container, set the `--workdir <directory>`
410+
option.
411+
412+
The following are some examples of container image and Batch container options or task command lines
413+
and their effect:
414+
415+
- Container image ENTRYPOINT isn't specified, and Batch task commandline is "/bin/sh -c python myscript.py".
416+
- Batch creates the container with the Batch task commandline as specified and runs it in the Batch
417+
task working directory. This may result in failure if "myscript.py" isn't in the Batch task working
418+
directory.
419+
- If the task commandline was specified as "/bin/sh -c python /path/to/script/myscript.py", then this task may
420+
work correctly even with the working directory set as the Batch task working directory if all dependencies
421+
for the script are satisfied.
422+
- Container image ENTRYPOINT is specified as "./myscript.sh", and Batch task commandline is empty.
423+
- Batch creates the container relying on the ENTRYPOINT and runs it in the Batch task working directory. This
424+
task may result in failure if the container image WORKDIR isn't the same as the Batch task working
425+
directory, which is dependent upon various factors such as the operating system, job ID, task ID, etc.
426+
- If "--workdir /path/to/script" was specified as a containerRunOption, then this task may work correctly if
427+
all dependencies for the script are satisfied.
428+
- Container image ENTRYPOINT isn't specified, Batch task commandline is "./myscript.sh", and WORKDIR is overridden in ContainerRunOptions as "--workdir /path/to/script".
429+
- Batch creates the container with the working directory to "/path/to/script" and execute the
430+
commandline "./myscript.sh", which is successful as the script is found in the specified working directory.
405431

406432
### Container task working directory
407433

@@ -419,6 +445,9 @@ For a Batch container task:
419445
420446
These mappings allow you to work with container tasks in much the same way as non-container tasks. For example, install applications using application packages, access resource files from Azure Storage, use task environment settings, and persist task output files after the container stops.
421447

448+
Regardless of how the WORKDIR is set for a container image, both `stdout.txt` and `stderr.txt`
449+
are captured into the `AZ_BATCH_TASK_DIR`.
450+
422451
### Troubleshoot container tasks
423452

424453
If your container task doesn't run as expected, you might need to get information about the WORKDIR or ENTRYPOINT configuration of the container image. To see the configuration, run the [docker image inspect](https://docs.docker.com/engine/reference/commandline/image_inspect/) command.

0 commit comments

Comments
 (0)