jobs.job.container definition

Container jobs allow you to run jobs on a container instead of the agent host.

Definitions that reference this definition: pipeline, jobs.job, jobs.deployment

Definitions that reference this definition: pipeline, jobs.job

Implementations

Implementation Description
container: string Specify job container by alias.
container: image Specify job container using image tag and options.

container: string

Specify job container by alias.

container: string # Specify job container by alias.

container string.

Specify job container by alias.

Remarks

The alias can be the name of an image, or it can be a reference to a container resource.

Examples

The following example fetches the ubuntu image tagged 18.04 from Docker Hub and then starts the container. When the printenv command runs, it happens inside the ubuntu:18.04 container.

pool:
  vmImage: 'ubuntu-18.04'

container: ubuntu:18.04

steps:
- script: printenv

container: image

Specify job container using image tag and options.

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  mapDockerSocket: boolean # Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.
  mountReadOnly: # Volumes to mount read-only, the default is all false.
    work: boolean # Mount the work directory as readonly.
    externals: boolean # Mount the externals directory as readonly.
    tools: boolean # Mount the tools directory as readonly.
    tasks: boolean # Mount the tasks directory as readonly.

Properties

image string. Required.
Container image tag.

endpoint string.
ID of the service endpoint connecting to a private container registry.

env string dictionary.
Variables to map into the container's environment.

mapDockerSocket boolean.
Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.

options string.
Options to pass into container host.

ports string list.
Ports to expose on the container.

volumes string list.
Volumes to mount on the container.

mountReadOnly mountReadOnly.
Volumes to mount read-only, the default is all false.

container: image

Specify job container using image tag and options.

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  mapDockerSocket: boolean # Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.

Properties

image string. Required.
Container image tag.

endpoint string.
ID of the service endpoint connecting to a private container registry.

env string dictionary.
Variables to map into the container's environment.

mapDockerSocket boolean.
Set this flag to false to force the agent not to setup the /var/run/docker.sock volume on container jobs.

options string.
Options to pass into container host.

ports string list.
Ports to expose on the container.

volumes string list.
Volumes to mount on the container.

container: image

Specify job container using image tag and options.

container:
  image: string # Required. Container image tag.
  endpoint: string # ID of the service endpoint connecting to a private container registry.
  env: # Variables to map into the container's environment.
    string: string # Name/value pairs
  options: string # Options to pass into container host.
  ports: [ string ] # Ports to expose on the container.
  volumes: [ string ] # Volumes to mount on the container.

Properties

image string. Required.
Container image tag.

endpoint string.
ID of the service endpoint connecting to a private container registry.

env string dictionary.
Variables to map into the container's environment.

options string.
Options to pass into container host.

ports string list.
Ports to expose on the container.

volumes string list.
Volumes to mount on the container.

Examples

Use options to configure container startup.

container:
  image: ubuntu:18.04
  options: --hostname container-test --ip 192.168.0.1

steps:
- script: echo hello

In the following example, the containers are defined in the resources section. Each container is then referenced later, by referring to its assigned alias.

resources:
  containers:
  - container: u14
    image: ubuntu:14.04

  - container: u16
    image: ubuntu:16.04

  - container: u18
    image: ubuntu:18.04

jobs:
- job: RunInContainer
  pool:
    vmImage: 'ubuntu-18.04'

  strategy:
    matrix:
      ubuntu14:
        containerResource: u14
      ubuntu16:
        containerResource: u16
      ubuntu18:
        containerResource: u18

  container: $[ variables['containerResource'] ]

  steps:
  - script: printenv

See also