Run docker container on azure - azure

I have a simple docker container which runs just fine on my local machine. I was hoping to find an easy checklist how I could publish and run my docker container on Azure, but couldn't find one. I only found https://docs.docker.com/docker-for-azure/, but this document kind of leaves me alone when it comes to actually copy my local docker container to Azure. Isn't that supposed to be very easy? Can anybody point me in the right direction how to do this?

But it is really easy.. once you know where to find the docs :-). I would take the azure docs as a starting point as there are multiple options when it comes to hosting containers in Azure:
If you're looking for this...
Simplify the deployment, management, and operations of Kubernetes -> Azure Container Service (AKS)
Easily run containers on Azure with a single command -> Container Instances
Store and manage container images across all types of Azure deployments
-> Container Registry
Develop microservices and orchestrate containers on Windows or Linux
-> Service Fabric
Deploy web applications on Linux using containers
-> App Service
Based on your info I would suggest storing the image using the Azure Container Registry and host the container using Azure Container Instances. No need for a VM to manage this way.
There is an excellent tutorial you could follow (I skipped the first 1 step since it involves creating a docker image, you already have one)
Another complete guide of pushing your image to azure and create a running container can be found here.
The good thing about Azure Container Instances is that you only pay for what you actually use. The Azure Container Registry is a private image repository hosted in Azure, if course you could also use Docker Hub but using ACR makes it all really simple.

In order to run an image, you simply need to configure a new VM with the Docker Daemon. I personally found Azure's documentation to be pretty complex. Assuming you are not trying to scale your service across instances, I would recommend using docker-machine rather than the Azure guide.
docker-machine is a CLI tool published by the Docker team which automatically installs the Docker Daemon (and all the dependencies) on a host. So all you would need to do is input your Azure subscription and it will automatically create a VM configured appropriately.
In terms of publishing the image, Azure is probably not the right solution. I would recommend one of two things:
Use Docker Hub, which serves as a free hosted Docker image repository. You can simply push images to Docker Hub (or even have them built directly from your Git repository).
Configure a CD tool, such as TravisCI or CircleCI, and use these to build your image and push directly to your deployment.

To run your docker image inside ACI, You can use of Azure Container Registry.
Step0: Create Azure Container Registry
Step1: Include a Dockerfile in your application code
Step2: Build the code along with the Dockerfile with a tag and create a
Docker image ( docker build -t imagename:tag .)
Step3: Push the Docker image to Azure container Registry with a image name and tag.
Step4: Now create a ACI, while creating, choose the image type as private, provide the image name, tag, image registry login server, image registry username, image registry password ( these details can be found under access keys tab inside Azure Container Registry)
Step5: choose running os as linux, in network step you can give an dns name for your ACI, then click on review & create
Step6: once ACI gets created you can go to overview and you can see fqdn, using fqdn you can access your application running inside Azure Container Instance.

Related

How to get Docker Images from Azure container registry and run onpremise servers using docker-compose?

I am using azure devops for CI/CD pipelines and one thing I couldn't find out, getting images from Azure container registry and run those images inside of my onpremise debian server. (I build and pushed the images to ACR already).
On release pipeline section:
I set Azure Container repository as source type and selected the latest artifact from there
then created a dev stage
Added a Command line tool to execute some scripts on server
-->This is the step where I lost<-- I need somehow to get these image from repository and fire compose up command in the server.
Extra info: you cannot use your docker-compose.yml(which mine is inside of the azure repo in same project) because you are using ACR as source type, not the build itself or source code.
*in my humble opinion this is a good case to enrich a content. Because there is lack of docs and videos on internet.
thanks,

How do I run a dockerized 'Hello World' web job deployed into Virtual Kubelet within Azure Kubernetes Service (AKS)

I did create a simple 'Hello World' Web Job and placed that Web Job inside a Docker Windows Container/Nanoserver
I did push that Docker Windows Container into an Azure Container Registry
I did follow this article and successfully created Virtual AKS pods/nodes
When I run 'get pods' I do see the pods created and running
I do see IP's generated reflected in the 'get pods' command
My question is how do I run the container inside these pods/nodes?
I did try to reference the IP's but those IP's don't load anything
How can I run those containers that I successfully placed into Virtual Kubelet pods/nodes
If the containers in the get fired up by themselves, do they fire up/get invoked only once or every n number of minutes?
Is there a way to check on how the last run went, like log files?
Thank you very much for your help
First of all, I see you create your web job inside a Windows-based Docker. If so, you cannot run the container in the AKS while it does not support Windows nodes, at least current. For window container, I suggest you could use the Azure Container Instance or Web App for Container.
For Linux containers, the pod in AKS is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers. If you already have the Docker image, you can create the container inside the pod follow the steps in Running the application in AKS.
In addition, you can set the restart policy for your container. See Restart Policy for the container in Kubernetes. For the logs, I suggest you could use the persist volumes. If not, the files will be lost if the container crash.\
Update
If you really want to run windows container in AKS cluster, there is also a way for you. You can use the virtual Kubelet and Azure Container Instance in AKS. Follow the steps Run Windows container in AKS.

Setup Azure Pipelines for a Azure multi container app (multiple repositories)

I currently have a web app split into three parts. Each part has its own git repository.
Frontend Angular (foo.bar)
Backend Angular (foo.bar/admin)
.NET Core API (foo.bar/api)
In front sits an NGINX Server which acts as a reverse proxy. Currently, it all runs on a VM together with a Jenkins Server which allows me to develop and deploy each part separately, which I really like.
I would like to containerize the application and move it to Azure Web Service for Containers. For the CD/CI I would like to use Azure DevOps & Azure Pipelines. Since Azure Web Service for Containers supports multi-container via Docker Compose and Kubernetes.
The main question is:
How can I build and deploy one specific container (e.g. Azure/frontend:10) in the multi-container (via Docker Compose) environment? (Without building all the other containers)
If that is possible...
How do I set up the Azure Pipelines and Azure Container Registry to allow me separate container deployments
Where does the docker-compose file live? In a separate repository?
Where does the reverse proxy NGINX Dockerfile live? In a separate repository as well?
Or do I need to use Kubernetes?
Alternately I could use three different App Webs on the same Service Plan and control it per domain/sub-domain.
Frontend Angular (foo.bar)
Backend Angular (admin.foo.bar)
.NET Core API (api.foo.bar)
I don’t know where to start. It is a small project too. I don’t want to make it too complicated.
Any tip is more than welcome.
Thanks in advance!
I do not have experience with Azure Pipelines, but there are some ideas about Azure Container Registry and the Azure Web App for Container.
First, if you just want to build one specific container in the multi-container via Docker compose, you can just set this in the tutorial:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
The compose also can be work with one container set in the file.
Second, the compose file can be everywhere that you run the command to create Web App for Container. For example, you can run the CLI command in your local machine with the compose file that store in your local machine.
Third, if you use Azure Web App for Container, you should prepare the docker image ready before in your repository, for example, the Azure Container Registry. It does not like docker compose installed in your local machine.
The AKS is also a good choice. You can create the service one by one or set them all in one yaml file. It's quite flexible.
Hope this will help you. If you need more help about the AKS or ACR please give the message.
You can use a container registry which will allow you to use docker to build each individual containers. You can then deploy a multi container app using containers from the container registry.
Building the container file follows the standard methods allowing you to copy configure and so forth. Once built you can push these by tagging them as follows: container_registry_name/container_name:{{.Run.ID}}
I would suggest based on the provided sample using a production database instead of a container as I have run into issues where a db data gets reset on container restart. Volumes for files can be persisted with the below:
${WEBAPP_STORAGE_HOME}/something/another:/var/www/html
Docker-Compose for containers does not (currently) allow you to use build in the azure pipeline as its meant for deployment only
One will need first build the dockerfiles and then reference your newly stored container registry images in docker-compose.yml. Also please take note that you cannot simply reference a docker hub image and a container registry image in the same compose file. You will need to pull and tag or build and tag the container to use it in that way. You can either use container registry images or public images.
In order to for your app to be able to connect to these images you need to add this to your app settings as well as allow admin in the container registry service:
DOCKER_REGISTRY_SERVER_USERNAME = [azure-container-registry-name]
DOCKER_REGISTRY_SERVER_URL = [azure-container-registry-name].azurecr.io
DOCKER_REGISTRY_SERVER_PASSWORD = [password]
Once you have your basic app setup you can then configure your continous integration options for further development such as webhooks, build options and so forth.

Moving existing docker image to Azure

We have an existing docker container which is running an dotnet core website. Requirement is to move this container to Azure and run website over cloud.
All tutorials or Howtos point at creating new docker image.Can someone provide me a link or direction to achieve this requirement.
Just push the image to a docker repository that is accesible externally and pull the image from there. Depending on what you use (vms\webapp\container instances) procedures for pulling will be different. For vm's - regular procedure, for webapps - this for container instances - this

What is container orchestration?

I have a GitLab repo, which uses docker container registry.
I want to push some of built containers to production using only one button click.
I heard that Kubernetes and Docker Swarm can help me, but I don't understand what it is
Can you explain in human language what is docker swarm and how can I use it to solve my task?
I want to push some of built containers to production using only one button click
You don't need docker orchestration for that, just docker.
More specifically, docker image push (previously docker push)
see "GitLab Using Docker Build"
Container orchestration is what is needed to transition from deploying containers individually on a single host, to deploying complex multi-container apps on many machines.
That is not what you are trying to do here: you just need to push images to a registry.

Resources