This process shows how to deploy MariaDB in a Docker container running on an Azure VM instance. First we'll create the Azure VM, then we'll deploy Docker to it. After that, we'll pull the MariaDB Docker image which we'll use to create a running container with a MariaDB instance. Finally, we'll load a sample database into the MariaDB instance.
Create a VM in Azure
Install MariaDB client on your local machine, either bundled with Maria DB server or standalone.
Login to Azure, navigate to Azure Virtual Machine
. Give the VM a name (e.g. mrdb-ubuntu-docker-use1), and create new or use an existing resource group. Selection region and availability zone, and choose Ubuntu 22.04 LTS x64 (free services eligible).
Choose the VM instance size, like a B1s or similar free tier. Note that Azure free works on a credit based system for new accounts
Configure an administrator account and generate a new key pair, and give the key pair a name.
Click "Review + Create" at the very bottom of the "create virtual machine" page to create the VM.
Download the SSH keys and them in a safe place, you will need them later. For this example, let's name the key file mrdb-docker-pk.pem.
If your local machine is Linux or you are using WSL on Windows, open a terminal window and:
Once the VM is deployed, "click to resource" to get back to the virtual machine's overview page.
From the overview page, the left-hand navigation, choose settings > networking.
Click "add inbound port rule"
Install Docker on the Azure VM
For more detailed instructions, refer to
To connect to your remote server using SSH, open a terminal window and use the following command, replacing placeholders with your specific details:
Replace your-keyfile.pem with your private key file name.
Replace your.ip.address with your actual IP address from step 12.
If you forget your admin details, go to Azure's left-hand navigation, select Settings >
Pull the MariaDB Docker image and create the container
To download the latest MariaDB Docker image, run the following command:
To start the MariaDB Docker process, open your terminal or command line and enter the following command:
Use the -v flag to mount a directory for persistent storage under /var/lib/mysql.
23. To login to MRDB inside the container, use the root password from step 20:
24. Setup admin account with permission for remote connection, configure access control
Obviously replace these passwords with something that is a bit more secure than you see in this example for anything other than development purposes.
Setup service account for your app with permission for remote connection, configure access control
Obviously replace these passwords with something that is a bit more secure than you see in this example for anything other than development purposes.
Load up your database from your preexisting SQL script that contains ; ; and statements.
Open a new local terminal window and navigate to the directory containing your init.sql script. Then, run the command: mariadb --host=ww.xx.yyy.zzz --port=3306 --user=admin --password=admin -e "SOURCE init.sql", replacing ww.xx.yyy.zzz with your server's IP address.
This page is licensed: CC BY-SA / Gnu FDL
Navigate back to the virtual machine's overview page. Then copy the public IP address to the clipboard.
Are you sure you want to continue connecting (yes/no/[fingerprint])? Say yes
To switch to the root user, use the following command:
C:\Users\YourUID\Documents\YourDirName should be specified as shown above.Ensure paths are absolute, not relative.
Replace yoursecurepassword with a strong password, especially for environments beyond development.
To access the MariaDB container's shell, use the following command:








sudo sumv /mnt/c/ ~/.ssh/
chmod 400 ~/.ssh/ssh -i ~/.ssh/your-keyfile.pem azureuser@your.ip.addressMicrosoft Azure offers two machine types with pre-installed Docker. If you need to reinstall Docker or choose a machine type without Docker pre-installed, you can install it manually. Connect to your machine via SSH and use the following command:```bash
curl -fsSL get.docker.com | sudo sh
```docker pull mariadb:ltsdocker run --detach --name mariadb-docker -v C:\Users\YourUID\Documents\YourDirName:/var/lib/mysql:Z -p 3306:3306 -e MARIADB_ROOT_PASSWORD=yoursecurepassword mariadb:lts```bashdocker exec -it mariadb-docker bash
``````bash
mariadb -p'yoursecurepassword'
```MariaDB [(none)]> CREATE USER 'admin'@'%' IDENTIFIED BY 'admin';
MariaDB [(none)]> GRANT ALL ON *.* to 'admin'@'%' WITH GRANT OPTION;
MariaDB [(none)]> SHOW GRANTS FOR admin;MariaDB [(none)]> CREATE USER 'yourappname'@'%' IDENTIFIED BY 'yoursecurepassword';
MariaDB [(none)]> GRANT INSERT, UPDATE, DELETE ON _._ to 'yourappname'@'%';
MariaDB [(none)]> SHOW GRANTS FOR yourappname;
