My Windows Container in Azure Container Instances does not seem to be able to access the internet.
What can I do to access the internet from my Windows Container?
I had to execute this PowerShell command in the container during startup:
Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).IfIndex -ServerAddresses ('8.8.8.8')
Then my container was able to successfully resolve DNS and access the internet.
Executing this script in a RUN did not work, so I had to somehow execute it together with my already required CMD. I ended up doing it like this and it works:
CMD ["powershell", "-Command", "\"Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).IfIndex -ServerAddresses ('8.8.8.8')\"; cd c:\\app; .\\my.exe ui"]
Don't forget to escape \ and ".
Related
I have build a docker linux image which includes azure cli, kubectl and terraform installation. I have pushed the image to azure container registry and created a container instance manually with that image. My container is running successfully and I am able to connect to it from the azure portal.
But my requirement is, I have to run some Rest API commands which is provided by the microsoft to perform certain action on the container. I have followed below microsoft documentation for executing the rest api command.
Link: https://learn.microsoft.com/en-us/rest/api/container-instances/containers/execute-command#code-try-0
I just provided my container details and added body as below:
{
"command": "/bin/bash",
"terminalSize": {
"rows": 12,
"cols": 12
}
}
I have received 200 response after running the above command. But when I tried running some different commands I am getting the 200 response but output is not changing. Can someone please share the information like what commands I can execute in azure container instance through the rest api.
Actually, this REST API is for the exec command that executes the bash command in the container. So it will create a socket session to communicate with the container, the returns are the socket session and the password.
And for the exec command, also for this REST API, it only can execute the single command, like ls, /bin/bash. But if you want to execute multiple commands like ls -al or curl $url, then it will fail. Actually, ACI does not support running multiple commands through the REST API or the exec command. The solution is you use the Azure CLI command az container exec to run the bash command /bin/bash, it will create a socket session for you, like an SSH connection. Then you can run commands inside the container. Here is the screenshot:
I used following quick start doc to spin up my first Azure container.
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-quickstart#feedback
It worked fine. but how do I connect to container if I want to debug something?
You cannot connect to the container itself directly to debug, IE you can't SSH or RDP to it. Take a look at this graphic which highlights how a container differs from virtual machines:
You can however pull logs from your container from the container engine. In your case you would want to use the following command in the Azure CLI: az container logs.
https://aka.ms/container_logs
When you invoke CLI through the Portal, you should already be connected through your subscription.To debug or troubleshoot you can look at the container logs. Check out this documentation for the exact commands
https://learn.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az-container-logs
When I am building containers to run on ACI, I build them first in a local docker instance where they can be connected to and interactively debugged. When you're happy with how they run locally push them into ACI, and debug from the output logs if needed.
I get to the bash shell in my Azure containers by either the azure-cli package, as the OP noted in a comment:
az container exec --exec-command "/bin/bash"
Or by navigating to a container instance in the Azure portal, then under Settings/Containers there is a "Connect" tab:
I am working on setting up environment for deploying microservices.
I have gotten as far as building my code and deploying to a registry but having problem running it in Azure Container Services.
I am following this guide to connect to ACS: https://learn.microsoft.com/en-us/azure/container-service/container-service-connect
But i fail on the step: Download Cluster Credentials
Using the given command
az acs kubernetes get-credentials --resource-group=<cluster-resource-group> --name=<cluster-name>
Ofc changing the reseource group and clustername to the correct names from my portal. I get an error:
[WinError 10049] The requested address is not valid in its context
(if i change resource group or clustername to something else I get other errors so seems it can find those at least)
When i try to search for the error it seems to be some IP adress problem but can't figure out what to do. Tried running same command from other network (from home) to make sure work firewall is not blocking something.. but I get the same error
Any help appriciated!
This command copy the cluster credentials to your machine. Background processes are ssh to your cluster VM and copy the credentials.
So, you should ensure you could ssh to the master VM manual. If you could not ssh to master VM manual, az command also could not do it. You could get your master-dns-name on Azure Portal.
ssh -i id_rsa <user>#<master-dns-name>
Notes: If az command does not work and you could ssh to master VM, you could download credentials to your machine. They are same. You could check your link about this.
You also need check your azure cli version. You could use the following commands
az --version
My version is 2.02. It works for me.
I have run an IIS from the official image (https://hub.docker.com/r/microsoft/iis/)
on windows Server 2016
Is there any way to connect to that IIS from an IIS Manager so I could have a GUI Access to that IIS?
I don't have a solution for you, but I do have a recommendation:
The core concept behind Docker is that all your application configuration is expressed as code. I recommend creating a Dockerfile (one per service) which uses FROM microsoft/iis and configure the site within, including all site files. This ensures that wherever your created image is launched, it will run exactly as you designed.
Docker is a paradigm shift. I wouldn't recommend expecting things to work exactly as they did before.
Use the following docker file:
FROM mcr.microsoft.com/windows/servercore/iis
SHELL [ "powershell" ]
#setup Remote IIS management
RUN Install-WindowsFeature Web-Mgmt-Service; \
New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force; \
Set-Service -Name wmsvc -StartupType automatic;
#Add user for Remote IIS Manager Login
RUN net user iisadmin Password~1234 /ADD; \
net localgroup administrators iisadmin /add;
Build it using docker build -t iisremote .
Run it using docker run --name remoteiis -d iisremote
Get the IP address of the container using docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' remoteiis
Connect to the container in IIS using the IP address optioned above
and the username and password used in the dockerfile
If you do not have the option in IIS to connect to a server, then you will need to install IIS Manager for Remote Administration from here. See this serverfault question for more info.
Note
When I tried creating a container directly from the IIS image (without the local dockerfile), connecting to the container using a terminal, and running the same powershell commands (that are in the dockerfile above) directly in the container terminal it does not work.
Source
https://devblogs.microsoft.com/premier-developer/iis-remote-management-for-docker-containers/
There is a solution to it, which contains of following parts.
1. You need to create local username/password in Container Image
2. You need to install IIS configuration tools
Detailed instructions are in walkthrough below
https://github.com/artisticcheese/artisticcheesecontainer/wiki
I am trying to use the Azure Command Line Tools (http://www.windowsazure.com/en-us/manage/linux/how-to-guides/command-line-tools/) to create an Ubuntu 12.04 VM.
I am issuing the following commands:
azure vm create xxxxxxxxxx.cloudapp.net b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_1-LTS-amd64-server-20121218-en-us-30GB azureuser mypassword --location "West Europe"
azure vm endpoint create xxxxxxxxxx 22 22
azure vm start xxxxxxxxxx
This seems to create and start the VM successfully.
I try to connect via SSH to the VM using the following command (on Mac OS X)
ssh azureuser#xxxxxxxxxx.cloudapp.net
However, when I try to SSH into the VM, it seems that password authentication is disabled on the VM as I am getting the following error:
Permission denied (publickey).
I would like to add that connecting via SSH to an Ubuntu VM created trough the Azure Management portal works absolutely fine. This issue only appears when the VM was created through the Azure command line tools.
Has anybody encountered a similar issue and knows how to solve it?
You need to use the --ssh switch on your azure vm create command to enable ssh. Adding the endpoint has no effect.
According to the Windows Azure command-line tool for Mac and Linux documentation you can only add ssh connectivity via the azure cli when the virtual machine is created.