简体   繁体   中英

Running docker commands in an Azure container

I've been struggling far longer than I should have on this and I'm sure I must be doing something the hard way.

Basically all I want to do is run a docker image in azure (the eos-dev blockchain image). I've gone through and created the container registry, enabled admin control and created the container using:

az container create --resource-group docker --name eosnode --image xxx.azurecr.io/eos-dev --cpu 1 --memory 14 --ip-address public --ports 80 7777 5555 --registry-password "zzz"

Now if this was a local docker instance id simply be able to run:

docker network create testnetwork

And I would get this back:

77af2f92d66895bbf71490b33d775a116d6d8d7be0cbd0a2b3d18ce7336cf611

Now, I'm attempting to do it on the remote azure container like this:

az container exec -g docker --name eosnode --container-name eosnode --exec-command "docker network create testnetwork"

But it returns nothing and I have no idea if it even did anything. What am I missing here?

As you say, you just want to run a docker image in Azure. And I see you create the container instance with the command:

az container create --resource-group docker --name eosnode --image xxx.azurecr.io/eos-dev --cpu 1 --memory 14 --ip-address public --ports 80 7777 5555 --registry-password "zzz"

For this step, the container instance is created in Azure. And you can get the instance information through the command az container show or get logs of the instance with the command az container log .

Also, you can execute the command inside the container instance using the command like this:

az container exec -g resrouceGroup -n instanceName "bash command"

But if you want to run the command docker network create testnetwork inside the container instance, you should install the docker inside the image which you create the container instance from.

docker network create

creates a docker network on the machine/host, the hash code returned is the id of the network. All 'docker' commands suppose to run on the host instead of in container. Docker network is not necessary to run container in Azure Container instance.

If a container image requires a command to start, usually the command can be found in its document/example with:

docker run <image> <command>

The equivalent way to run the container in azure container instance is:

az container create -g <resourceGroup> -n <name> --image <image> --command-line <command> --restart-policy <Always|OnFailure|Never>
  • --command-line: specify the command to run in the container

  • --restart-policy: Define the behavior when the command exit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM