B"H
I'd like to use Azure web apps to host staging servers for wordpress.
The best way to ensure that staging is as close as possible to live seems to be docker.
I use docker-compose on my dev machine and it works great. I would like to replicate that setup on azure.
My docker-compose.yml file sets up three containers 1) mysql 2) phpMyAdmin 3) my-wordpress-container
I mount three volumes
- ./data/mysql:/var/lib/mysql
- ./data/init/:/docker-entrypoint-initdb.d
in the db container and
- ./site/wp-content/uploads:/var/www/html/wp-content/uploads
in the wordpress container.
Most important is the /docker-entrypoint-initdb.d file for bootstrapping the db with test data.
How would I accomplish that in Azure web apps?
Before answering... Please do not explain how to deploy multiple containers on App services using docker-compose. Or post links to tutorials on hosting Wordpress in that environment. That is both simple and not quite enough for it to be useful.
Also, please do not post links about mounting File Shares in web apps. That is also quite simple.
The question is how to mount File Shares into a multi container setup. Specifically how I might be able to mount the /docker-entrypoint-initdb.d to bootstrap the db with test data.
This is totally doable in Container Instances. However there are other features that make it unusable for this solution.
I think this documentation is what you are looking for:
https://learn.microsoft.com/en-us/azure/app-service/containers/how-to-serve-content-from-azure-storage#use-custom-storage-in-docker-compose
From the docs:
Azure Storage can be mounted with multi-container apps using the custom-id. To view the custom-id name, run az webapp config storage-account list --name <app_name> --resource-group <resource_group>.
In your docker-compose.yml file, map the volumes option to custom-id. For example:
wordpress:
image: wordpress:latest
volumes:
- <custom-id>:<path_in_container>
There is a way to mount disks from Azure web apps, just google "mount disk from azure web app". There is a good blog post from TOM KERKHOVE.
However, I would advise you against this, currently the Azure Storage REST API appears more stable https://learn.microsoft.com/en-us/rest/api/storageservices/
Azure Web-Apps enables multi-containers in preview at the moment. Web-Apps does come with MySql as part of the instance. But not recommended for when you want to scale you Web-Application. So it is best to host the MySQL in MySQL as a service.
If you go to the link below it will walk you how to host Wordpress and Redis within Azure Web-App with multi-containers. Using My-SQL Service for the database and persistent storage.
https://learn.microsoft.com/en-gb/azure/app-service/containers/tutorial-multi-container-app
If you would still want to run MySQL in docker you may want to consider using Azure Kubernetes Service to host all the containers instead.
I hope this helps.
Related
I have a multi containers webapp deployed with mariadb container, I trying to mount with azure file share but it not work due to directory permission, Can I user docker create volume instead? I test stop start webapp, volume still there, will there be any problem? I couldnt find any explanation, anyone can answer here?
in docker compose file as follow:
version: '3.4'
volumes:
acl-database-data: {}
In Azure App Service, except mounting the Azure File Share and the persistent storage of app service, the volumes in the docker-compose just create the volumes tempprarily. And you can't create the volumes using the command docker create volume. Azure controls the docker command itself and it can't be customized. And when you use the volumes without Azure File Share, then the data will lose if you restart the app service, even if the volume doesn't disappear.
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.
I am trying to build two different services which will be running on Azure Web Apps for Containers. I am creating docker images and storing it in Azure Container Registry. I want to share single persistent storage between these two services. I understood from blogs that you can mount /home directory but could not be shared between two services.
There is plugin for docker Cloudstor, I can create the volume but not sure how we can utilize this generated volume in Web Apps For Containers. The app service runs the command for docker, does anybody know how we can use the volume created using the plugin?
In My Opinion the webapps for containers should not be there. I think it is better to get a docker host machine as vm and then work with normal docker features. this is also the way microsoft describes in their docs for multi-docker szenarios. https://learn.microsoft.com/de-de/azure/virtual-machines/linux/docker-compose-quickstart
Things that should microsoft do:
give kudo a proper docker cli
map storages to docker volumes via azure dashboard/azure cli
Create a storage account and mount Fileshare into the docker image somewhere under /home
This will be easiest if the two service instances are in the same resource group as the storage account.
What is your reason for sharing a single storage instance?
Without experimenting I can't guarantee the same storage container can be shared between two app services. Depends on your needs. I expect two containers in the same storage account can be mounted into your two docker images.
Without knowing a little more this is the most I can contribute. All the best.
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.
I've deployed a Web App on Azure and use a Docker Container from the public registry (my own image) to host my website. But users can upload pictures and data is stored in json-files on the server. Of course I want to write these files to a mounted volume outside of the container. So that I can redeploy an update version of my website without losing data.
Is that possible with Web Apps? Or do I need to move on to an Ubuntu VM with Docker on Azure? What I like about the webapps is I don't have to worry about managing the VM and only care about my container.
This blog post is a great start and understanding Azure's strategy regarding volume mounting (ASL == App Services on
Linux; ASW=App Services on Windows):
... However, in this case, we would like to leverage the regular App Service Filesystem, so we can interact with the application using FTP. When a container is deployed, ASL mounts the equivalent of D:\home path on ASW to /home (using volume mount in Docker). Now when that happens, it is up to your container to map the corresponding paths into the application. In order to understand how this works more closely, take a look at the official Dockerfile used in PHP7 container on ASL.
https://hajekj.net/2016/12/25/building-custom-docker-images-for-use-in-app-service-on-linux/