Site icon 峰哥分享

Apply your local wordpress changes to Azure Container Instance

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.
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 WORDPRESS_DB_HOST=feng-test-mysql.mysql.database.azure.com \
 –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
ACI_PERS_RESOURCE_GROUP=testACI
ACI_PERS_STORAGE_ACCOUNT_NAME=testacistorage$RANDOM
ACI_PERS_LOCATION=eastus
ACI_PERS_SHARE_NAME=testacishare
 
# Create the storage account with the parameters
az storage account create \
    –resource-group $ACI_PERS_RESOURCE_GROUP \
    –name $ACI_PERS_STORAGE_ACCOUNT_NAME \
    –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)
 
echo $STORAGE_ACCOUNT
 
STORAGE_KEY=$(az storage account keys list –resource-group $ACI_PERS_RESOURCE_GROUP –account-name $STORAGE_ACCOUNT –query “[0].value” –output tsv)
echo $STORAGE_KEY
 
Now, we have a storage share ready. 
 
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/
But you can’t do much from here
You can also login to azure portal to manage it
Or use Azure Storage Explorer
Use the connection string in  AZURE_STORAGE_CONNECTION_STRING variable
This tool support uploading folders.
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 \
    -e WORDPRESS_DB_HOST=feng-test-mysql.mysql.database.azure.com\
     WORDPRESS_DB_USER=fennng@feng-test-mysql\
     WORDPRESS_DB_PASSWORD=password\
    –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.
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.zip wp-content/
Then you can upload the whole folder to Azure
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)
passwd
once changed, logout and login again. It may take a minute before the new password works.
Now, you should upload the wp-content.zip 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 wp-content.zip
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.
You are done.
Exit mobile version