How to log into container in Azure? - azure

I deploy a docker image inside Azure Container Instance. The application itself will write some log into the file. Is there some way I can log into the container to view these logs?

az container exec --resource-group <group-name> --name <container-group-name> --exec-command "<command>"
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-exec
You could also create a context with docker and then use docker commands.
docker context create aci myacicontext
docker context use myacicontext
docker logs <CONTAINER_ID>
docker exec -t <CONTAINER_ID> COMMAND
https://docs.docker.com/cloud/aci-integration/#create-an-aci-context

Have found the answer.
az container logs --name your-container-name --resource-group your-resource-group-name
or
az container exec --name your-container-name --resource-group your-resource-group-name --exec-command "cat /home/yourname/xxx.log"

Related

Connecting to a jenkins container running on azure

I'm currently running jenkins from a container on my azure container instances, but I'm having difficulty with connecting. I specified port 80 when I run the CLI command:
az container create -g MyResourceGroup --name MyName --image MyImage --ports 80
Is there something I missed or another way I could configure it from the portal so that I can connect and setup jenkins? Any help would be appreciated.
The possible reason is that your container instance is not accessible outside because you do not expose it to the Internet. If you want to expose it to the Internet, the command should be like this:
az container create -g MyResourceGroup --name MyName --image MyImage --ports 80 --ip-address Public
For more details, see parameter --ip-address in az container create.
Or you can connect into the container instance through the CLI command az container exec -g MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash" or exec the command in the portal.
In addition, it seems you run Jenkins in the container instance. I would not recommend you do this. Because the Container Instance is a light-weight service, if you run a server in it, then it won't be actually what it should be anymore. The VM is an appropriate host for the Jenkins server. See Jenkins in VM.
Did you specify the DNS name with the parameter --dns-name-label

Deploy image from docker hub to AZure

I want to deploy a image from docker hub to Azure Container Instance.How can we do this.Is it mandatory to push the image first to Azure Container Registry?
All solutions I am getting shows that we need to push the image first to Azure Container Registry.
No, you need not push the image to ACR first, just let the image stay in the docker hub. For example, deploy the Nginx docker image to ACI, the Azure CLI command like below:
az container create -g resourceGroup -n aciName --image nginx --ports 80
As the command shows, you can use the docker image. Actually, the docker hub is the default registry. When you use another registry, you need to add the parameters --registry-login-server, --registry-username and --registry-password. For more details, see az container create.
It also shows clearly in the Azure portal, when you create ACI in the portal, you can see it like below:
You can use docker image directly with the container as follows,
az container create --resource-group myResourceGroup --name mycontainer --image docker image url

Switch docker image in Azure appservice

going through tutorial https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image
Is it possible to switch docker image on already running appservice?
using this command:
az webapp config container set --name <app-name> --resource-group myResourceGroup --docker-custom-image-name <azure-container-registry-name>.azurecr.io/mydockerimage:v1.0.0 --docker-registry-server-url https://<azure-container-registry-name>.azurecr.io --docker-registry-server-user <registry-username> --docker-registry-server-password <password>
az webapp config container
You should go on deployment center.

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.

How do I stop an Azure Container Instance?

I'm still new to the Azure Container Instance scene. I have managed to complete the container instance tutorial. However, I've noticed that the tutorial does not show the reader how to stop a running container instance. The nearest command that gaurantees the container instance is indeed stopped / terminated, is by deleting the Resource Group which created the container.
az group delete -n <ResourceGroupNameThatCreatedContainerInstance>
Is this the correct approach?
The Azure CLI updated and now its possible.
Stop
az container stop --name
--resource-group
[--subscription]
Restart
az container restart --name
--resource-group
[--subscription]
You can use az container delete
az container delete -g MyResourceGroup --name mynginx

Resources