Monday, December 20, 2021

Deploy multi-container app to Azure App Service with docker-compose

In this article, I will show how easy it is to deploy a multi-container application to Azure App Service using a docker-compose.yml file. This service is currently in preview on Azure. The example is deployment of a WordPress site on the Azure portal. This involves two containers on docker hub, namely: mysql:8.0.0 and wordpress:5.8.2-php7.4-apache.

The only pre-requisite is that you have a valid Azure subscription.

Save the following to a text file named docker-compose.yml:

version: '3.1'

services:

  wordpress:
    image: wordpress:5.8.2-php7.4-apache
    restart: always
    ports:
      - 8888:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: mysql:8.0.0
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

Login to https://portal.azure.com. Create a new app service as follows:
  1. Create a new resource group
  2. Provide a unique host name for your app's URL
  3. Select 'Docker Container" for Publish
  4. Select Linux for the Operating System
  5. Choose a data center closest to your city


Click on the "Next Docker" button.
  1. Select 'Docker Compose (Preview)' for Options.
  2. Select 'Docker Hub' for Image Source
  3. Select Public for Access Type
  4. Beside 'Configuration File', navigate to the docker-compose.yml and select it.

Click on blue "Review + create" button.


Click on the blue Create button. It may take some time to provision the containers. Upon completion, you will see a page that looks like this:


Click on the blue "Go to resource" button.


Click on the URL to view the WordPress page.


Troubleshooting

If something goes wrong and you wish to look into the console logs:

1) Enter 'log' into the filter
2) Turn "App Service Logs" ON



3) Click Save at the top
4) Click on "Log stream"



Cleanup

If you do not need these containers anymore, all you have to do to tear down everything is to delete the resource group.

Conclusion

It is painless to create a multi-container web application using docker-compose.yml.



No comments:

Post a Comment