1

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?"],```
andryuha
  • 1,526
  • 3
  • 15
  • 31
  • can you share documentation ? I can't find anything that describes how to use containerGroups.beginCreateOrUpdate() using javascript. – deltascience Mar 07 '22 at 22:58

1 Answers1

1

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 :-)

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • @andryuha OK, wait for your message. – Charles Xu Apr 16 '19 at 05:40
  • @andryuha Anything else? Why not send me any response? – Charles Xu Apr 19 '19 at 01:12
  • CMD probably works, but container is immediately shut down and I need it to live till i shut it down. What i'm after is overridding ENTRYPOINT, doesn't look like azure api allows for that? – andryuha Apr 20 '19 at 02:34
  • @andryuha As I said in the answer **One**, if you want the container in the running state until you shut it down, you should use a keep running command, for example `tail -f /dev/null`. See the [description](https://learn.microsoft.com/en-us/azure/container-instances/container-instances-troubleshooting#container-continually-exits-and-restarts-no-long-running-process). – Charles Xu Apr 21 '19 at 12:48