Use Azure file as docker volumn on Azure linux VM

  • fennng 
I have a website running in azure container instance. I noticed that container instance is not cheaper than a linux VM. I would like to migrate to linux VM.
The process is quite simple.
Firstly, you need to create a linux VM from azure portal.
Then follow this website to get docker.
Most important command is sudo apt-get install docker-ce
Now you have docker installed.  You can run wordpress in docker easily. But I would like to link my new wordpress docker container to my existing azure file.
To do this, we need to install a plugin to allow VM to connect to azure file.
//download docker volume driver
// Move it
sudo mv azurefile-dockervolumedriver /usr/bin/
// make it executable
chmod +x /usr/bin/azurefile-dockervolumedriver
// Download this zip to get the two files
// install unzip
sudo apt install unzip
// unzip the file
unzip v0.5.1.zip
// copy the default file to the right location
sudo cp azurefile-dockervolumedriver-0.5.1/contrib/init/systemd/azurefile-dockervolumedriver.default /etc/default/azurefile-dockervolumedriver
// edit it to match your storage account
sudo vi /etc/default/azurefile-dockervolumedriver

You can get your storage info from azure portal

// Copy service file to right location
sudo cp azurefile-dockervolumedriver-0.5.1/contrib/init/systemd/azurefile-dockervolumedriver.service /etc/systemd/system/azurefile-dockervolumedriver.service
// Start the service, you will need to enter password for following four commands
systemctl daemon-reload
systemctl enable azurefile-dockervolumedriver
systemctl start azurefile-dockervolumedriver
systemctl status azurefile-dockervolumedriver

Use following commands to test, if myvol exist, it will use it, otherwise, a new store created.
sudo docker volume create -d azurefile –name myvol -o share=myvol
sudo docker run -i -t -v myvol:/data busybox
// Start a new wordpress instance
sudo docker volume create -d azurefile –name vol -o share=existStorageName
sudo docker run -d –name wp -v vol:/var/www/html -p 80:80 wordpress
Open http port from azure portal for the VM
All good, you can stop your old container instance now, don’t forget to update your dns to point to the new server.
​​

Feng
标签:

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注