Apply your local wordpress changes to Azure Container Instance

  • fennng 
In my last posts, I introduce how to create wordpress in azure container instance. I also demonstrated how to migrate your local mysql database to Azure mysql.
But migrating database will not affect your images in your gallery, and all your customized themes and plugins are still not yet live.
Inline image 1
You can create a changed docker image and upload to auzre.
But in this case, docker commit does not work because /var/www/html is a volumn.
You can find out which volumn is used by the container

docker inspect -f '{{ .Mounts }}' containerid 
You can start a new container to mount to the volumn and also connect to azure mysql server to test the volumn.
docker run –name some-wordpress -p 8011:80 -e \
 –mount source=3597ca843600a38db43fe553a5611d5c80c8365243a5f596236aa7bf95de7d91,target=/var/www/html \
    -e WORDPRESS_DB_USER=fennng@feng-test-mysql -e WORDPRESS_DB_PASSWORD=password  wordpress
The solution is putting your wordpress content on azure file share then mount your file share as a wordpress volume.
Firstly, let’s create a storage account.
# Change these four parameters as needed
# Create the storage account with the parameters
az storage account create \
    –resource-group $ACI_PERS_RESOURCE_GROUP \
    –location $ACI_PERS_LOCATION \
    –sku Standard_LRS
# Export the connection string as an environment variable. The following ‘az storage share create’ command
# references this environment variable when creating the Azure file share.
export AZURE_STORAGE_CONNECTION_STRING=`az storage account show-connection-string –resource-group $ACI_PERS_RESOURCE_GROUP –name $ACI_PERS_STORAGE_ACCOUNT_NAME –output tsv`
# Create the file share
az storage share create -n $ACI_PERS_SHARE_NAME
STORAGE_ACCOUNT=$(az storage account list –resource-group $ACI_PERS_RESOURCE_GROUP –query “[?contains(name,’$ACI_PERS_STORAGE_ACCOUNT_NAME’)].[name]” –output tsv)
STORAGE_KEY=$(az storage account keys list –resource-group $ACI_PERS_RESOURCE_GROUP –account-name $STORAGE_ACCOUNT –query “[0].value” –output tsv)
Now, we have a storage share ready. 
Inline image 1
You can use  acihellofilesto manage this volume 
az container create \
    –resource-group $ACI_PERS_RESOURCE_GROUP \
    –name hellofiles \
    –image seanmckenna/aci-hellofiles \
    –ip-address Public \
    –ports 80 \
    –azure-file-volume-account-name $ACI_PERS_STORAGE_ACCOUNT_NAME \
    –azure-file-volume-account-key $STORAGE_KEY \
    –azure-file-volume-share-name $ACI_PERS_SHARE_NAME \
    –azure-file-volume-mount-path /aci/logs/
Inline image 2
But you can’t do much from here
You can also login to azure portal to manage it
Inline image 3
Or use Azure Storage Explorer
Inline image 4
Use the connection string in  AZURE_STORAGE_CONNECTION_STRING variable
Inline image 5
Inline image 6
This tool support uploading folders.
Inline image 7
We will let wordpress to create wordpress for us.
Let’s recreate a wordpress container
 az container delete –name wp -g testACI
az container create \
    –resource-group $ACI_PERS_RESOURCE_GROUP \
    –name wp\
    –image wordpress \
    –ip-address Public \
    –ports 80 \
    –azure-file-volume-account-name $ACI_PERS_STORAGE_ACCOUNT_NAME \
    –azure-file-volume-account-key $STORAGE_KEY \
    –azure-file-volume-share-name $ACI_PERS_SHARE_NAME \
    –azure-file-volume-mount-path /var/www/html
Now, you should have your new wordpress working. Check your file share, you can see all the wordpress files generated by the container.
Inline image 8
But this is the original wordpress files.
You need to upload your local wp-content folder to overwrite the default one.
Now, let’s copy the wp-content file out to current directory
docker cp wp:/var/www/html/wp-content .
you can zip it to move to usb if needed.
zip -r wp-content/
Then you can upload the whole folder to Azure
Inline image 9
It will take a long time to upload a big folder.
It can be a good idea to create a container to unzip the file, make sure you backup and delete the wp-config.php file on the file share before doing this.
We will create an ubuntu container with ssh access.
az container create \
    –resource-group $ACI_PERS_RESOURCE_GROUP \
    –name ssh\
    –image rastasheep/ubuntu-sshd \
    –ip-address Public \
    –ports 22\
    –azure-file-volume-account-name $ACI_PERS_STORAGE_ACCOUNT_NAME \
    –azure-file-volume-account-key $STORAGE_KEY \
    –azure-file-volume-share-name $ACI_PERS_SHARE_NAME \
    –azure-file-volume-mount-path /root
now ssh to it using it’s ip address.
Note that you are in the risk of attacking.
So, the first thing to is changing the password, do this carefully, otherwise, you will not be able to login again. (you can still easily recreate the container)
once changed, logout and login again. It may take a minute before the new password works.
Now, you should upload the to the volume using azure portal or azure storage explorer. You can also use psftp if you want.
Once uploaded
in your ssh shell, run apt-get update && apt-get unzip
then run unzip
Now, type A to agree to replace all the files.
Wait for a few minutes.
Now, upload your wp-config.php file back to the server.
And then delete your ssh server.
az contain delete -n ssh -g testACI
Login to your wordpress, you plugins are back, but they are inactive. You have to reactive them.
Inline image 10
You are done.


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