az container

Manage Azure Container Instances.

Commands

az container attach Attach local standard output and error streams to a container in a container group.
az container create Create a container group.
az container delete Delete a container group.
az container exec Execute a command from within a running container of a container group.
az container export Export a container group in yaml format.
az container list List container groups.
az container logs Examine the logs for a container in a container group.
az container restart Restarts all containers in a container group.
az container show Get the details of a container group.
az container stop Stops all containers in a container group.

az container attach

Attach local standard output and error streams to a container in a container group.

az container attach --name
--resource-group
[--container-name]

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--container-name

The container to attach to. If omitted, the first container in the container group will be chosen.

az container create

Create a container group.

az container create --resource-group
[--azure-file-volume-account-key]
[--azure-file-volume-account-name]
[--azure-file-volume-mount-path]
[--azure-file-volume-share-name]
[--command-line]
[--cpu]
[--dns-name-label]
[--environment-variables]
[--file]
[--gitrepo-dir]
[--gitrepo-mount-path]
[--gitrepo-revision]
[--gitrepo-url]
[--image]
[--ip-address {Public}]
[--location]
[--log-analytics-workspace]
[--log-analytics-workspace-key]
[--memory]
[--name]
[--network-profile]
[--no-wait]
[--os-type {Linux, Windows}]
[--ports]
[--protocol {TCP, UDP}]
[--registry-login-server]
[--registry-password]
[--registry-username]
[--restart-policy {Always, Never, OnFailure}]
[--secrets]
[--secrets-mount-path]
[--secure-environment-variables]
[--subnet]
[--subnet-address-prefix]
[--vnet-address-prefix]
[--vnet-name]

Examples

Create a container in a container group with 1 core and 1Gb of memory.

az container create -g MyResourceGroup --name myapp --image myimage:latest --cpu 1 --memory 1

Create a container in a container group that runs Windows, with 2 cores and 3.5Gb of memory.

az container create -g MyResourceGroup --name mywinapp --image winappimage:latest --os-type Windows --cpu 2 --memory 3.5

Create a container in a container group with public IP address and ports.

az container create -g MyResourceGroup --name myapp --image myimage:latest --ip-address public --ports 80 443

Create a container in a container group with public IP address and UDP port.

az container create -g MyResourceGroup --name myapp --image myimage:latest --ip-address public --ports 8081 --protocol UDP

Create a container in a container group with public IP address, ports and DNS name label.

az container create -g MyResourceGroup --name myapp --image myimage:latest --ports 80 443 --dns-name-label contoso

Create a container in a container group that invokes a script upon start.

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "/bin/sh -c '/path to/myscript.sh'"

Create a container in a container group that runs a command and stop the container afterwards.

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "echo hello" --restart-policy Never

Create a container in a container group with environment variables.

az container create -g MyResourceGroup --name myapp --image myimage:latest -e key1=value1 key2=value2

Create a container in a container group using container image from Azure Container Registry.

az container create -g MyResourceGroup --name myapp --image myAcrRegistry.azurecr.io/myimage:latest --registry-password password

Create a container in a container group using container image from another private container image registry.

az container create -g MyResourceGroup --name myapp --image myimage:latest --cpu 1 --memory 1.5 --registry-login-server myregistry.com --registry-username username --registry-password password

Create a container in a container group that mounts an Azure File share as volume.

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "cat /mnt/azfile/myfile" --azure-file-volume-share-name myshare --azure-file-volume-account-name mystorageaccount --azure-file-volume-account-key mystoragekey --azure-file-volume-mount-path /mnt/azfile

Create a container in a container group that mounts a git repo as volume.

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "cat /mnt/gitrepo" --gitrepo-url https://github.com/user/myrepo.git --gitrepo-dir ./dir1 --gitrepo-mount-path /mnt/gitrepo

Create a container in a container group using a yaml file.

az container create -g MyResourceGroup -f containerGroup.yaml

Create a container group using Log Analytics from a workspace name.

az container create -g MyResourceGroup --name myapp --log-analytics-workspace myworkspace

Create a container group using Log Analytics from a workspace id and key.

az container create -g MyResourceGroup --name myapp --log-analytics-workspace workspaceid --log-analytics-workspace-key workspacekey

Required Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--azure-file-volume-account-key

The storage account access key used to access the Azure File share.

--azure-file-volume-account-name

The name of the storage account that contains the Azure File share.

--azure-file-volume-mount-path

The path within the container where the azure file volume should be mounted. Must not contain colon ':'.

--azure-file-volume-share-name

The name of the Azure File share to be mounted as a volume.

--command-line

The command line to run when the container is started, e.g. '/bin/bash -c myscript.sh'.

--cpu

The required number of CPU cores of the containers, accurate to one decimal place.

default value: 1
--dns-name-label

The dns name label for container group with public IP.

--environment-variables -e

A list of environment variable for the container. Space-separated values in 'key=value' format.

--file -f

The path to the input file.

--gitrepo-dir

The target directory path in the git repository. Must not contain '..'.

default value: .
--gitrepo-mount-path

The path within the container where the git repo volume should be mounted. Must not contain colon ':'.

--gitrepo-revision

The commit hash for the specified revision.

--gitrepo-url

The URL of a git repository to be mounted as a volume.

--image

The container image name.

--ip-address

The IP address type of the container group.

accepted values: Public
--location -l

Location. You can configure the default location using az configure --defaults location=<location>.

--log-analytics-workspace

The Log Analytics workspace name or id. Use the current subscription or use --subscription flag to set the desired subscription.

--log-analytics-workspace-key

The Log Analytics workspace key.

--memory

The required memory of the containers in GB, accurate to one decimal place.

default value: 1.5
--name -n

The name of the container group.

--network-profile

The network profile name or id.

--no-wait

Do not wait for the long-running operation to finish.

--os-type

The OS type of the containers.

accepted values: Linux, Windows
default value: Linux
--ports

The ports to open.

default value: [80]
--protocol

The network protocol to use.

accepted values: TCP, UDP
--registry-login-server

The container image registry login server.

--registry-password

The password to log in container image registry server.

--registry-username

The username to log in container image registry server.

--restart-policy

Restart policy for all containers within the container group.

accepted values: Always, Never, OnFailure
default value: Always
--secrets

Space-separated secrets in 'key=value' format.

--secrets-mount-path

The path within the container where the secrets volume should be mounted. Must not contain colon ':'.

--secure-environment-variables

A list of secure environment variable for the container. Space-separated values in 'key=value' format.

--subnet

The name of the subnet when creating a new VNET or referencing an existing one. Can also reference an existing subnet by ID.

--subnet-address-prefix

The subnet IP address prefix to use when creating a new VNET in CIDR format.

default value: 10.0.0.0/24
--vnet-address-prefix

The IP address prefix to use when creating a new VNET in CIDR format.

default value: 10.0.0.0/16
--vnet-name

The name of the VNET when creating a new one or referencing an existing one.

az container delete

Delete a container group.

az container delete --name
--resource-group
[--yes]

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--yes -y

Do not prompt for confirmation.

az container exec

Execute a command from within a running container of a container group.

az container exec --exec-command
--name
--resource-group
[--container-name]
[--terminal-col-size]
[--terminal-row-size]

Examples

Stream a shell from within an nginx container.

az container exec -g MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash"

Required Parameters

--exec-command

The command to run from within the container.

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--container-name

The container name where to execute the command. Can be ommitted for container groups with only one container.

--terminal-col-size

The col size for the command output.

default value: 80
--terminal-row-size

The row size for the command output.

default value: 20

az container export

Export a container group in yaml format.

az container export --file
--name
--resource-group

Examples

Export a container group in yaml.

az container export -g MyResourceGroup --name mynginx -f output.yaml

Required Parameters

--file -f

The file path to export the container group.

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az container list

List container groups.

az container list [--resource-group]

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az container logs

Examine the logs for a container in a container group.

az container logs --name
--resource-group
[--container-name]
[--follow]

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--container-name

The container name to tail the logs. If omitted, the first container in the container group will be chosen.

--follow

Indicate to stream the tailing logs.

az container restart

Restarts all containers in a container group.

az container restart --name
--resource-group

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az container show

Get the details of a container group.

az container show --name
--resource-group

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az container stop

Stops all containers in a container group.

az container stop --name
--resource-group

Required Parameters

--name -n

The name of the container group.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.