dockerazure-container-registryazure-sdkazure-container-instancesazure-node-sdk

how do you properly pass a command to a container when using "azure-arm-containerinstance" from azure node sdk?


just looking for some guidance on how to properly invoke a command when a container starts, when creating it via azure-arm-containerinstance package. There is very little documentation on this specific part and I wasn't able to find any examples out there on the internet.

return client.containerGroups
                    .beginCreateOrUpdate(process.env.AZURE_RESOURCE_GROUP, containerInstanceName, {
                        tags: ['server'],
                        location: process.env.AZURE_INSTANCE_LOCATION,
                        containers: [
                            {
                                image: process.env.CONTAINER_IMAGE,
                                name: containerInstanceName,
                                command: ["./some-executable","?Type=Fall?"],
                                ports: [
                                    {
                                        port: 1111,
                                        protocol: 'UDP',
                                    },
                                ],
                                resources: {
                                    requests: {
                                        cpu: Number(process.env.INSTANCE_CPU),
                                        memoryInGB: Number(process.env.INSTANCE_MEMORY),
                                    },
                                },
                            },
                        ],
                        imageRegistryCredentials: [
                            {
                                server: process.env.CONTAINER_REGISTRY_SERVER,
                                username: process.env.CONTAINER_REGISTRY_USERNAME,
                                password: process.env.CONTAINER_REGISTRY_PASSWORD,
                            },
                        ],```

Specifically this part below, is this correct? Just an array of strings? Are there any good examples anywhere? (tried both google and bing) Is this equivalent of docker's CMD ["command","argument"]?

```command: ["./some-executable","?Type=Fall?"],```

Solution

  • With your issue, most you have done is right, but there are points should pay attention to.

    one is the command property will overwrite the CMD setting in the Dockerfile. So if the command will not always keep running, then the container will in a terminate state when the command finish execute.

    Second is the command property is an array with string members and they will execute like a shell script. So I suggest you can set it like this:

    command: ['/bin/bash','-c','echo $PATH'],
    

    And you'd better keep the first two strings no change, just change the after.

    If you have any more questions please let me know. Or if it's helpful you can accept it :-)