Persisting content across docker restart within an Azure Web App
Asked Answered
L

5

5

I'm trying to run a ghost docker image on Azure within a Linux Docker container. This is incredibly easy to get up and running using a custom Docker image for Azure Web App on Linux and pointing it at the official docker hub image for ghost.

Unfortunately the official docker image stores all data on the /var/lib/ghost path which isn't persisted across restarts so whenever the container is restarted all my content get's deleted and I end up back at a default ghost install.

Azure won't let me execute arbitrary commands you basically point it at a docker image and it fires off from there so I can't use the -v command line param to map a volume. The docker image does have an entry point configured if that would help.

Any suggestions would be great. Thanks!

Lentil answered 24/8, 2017 at 13:24 Comment(0)
W
2

You have a few options:

  1. You could mount a file share inside the Docker container by creating a custom image, then storing data there. See these docs for more details.
  2. You could switch to the new container instances, as they provide volume support.
  3. You could switch to the Azure Container Service. This requires an orchestrator, like Kubernetes, and might be more work than you're looking for, but it also offers more flexibility, provides better reliability and scaling, and other benefits.
Weft answered 24/8, 2017 at 17:55 Comment(4)
Thanks, option 1 looks like it might have some potential although I'm assuming I then need to bake my file share access key into the docker build which makes it impossible to share with anyone.Lentil
You didn't mention sharing in your question, so it's hard to understand your scenario, but you might specify the file share key as an environment variable so that others can specify their own key.Weft
You're right I didn't I was just thinking if I was going to build a custom dockerfile for this I'd want to be able to share it. I'm going to try out creating a custom image with an environment variable and see how that works.Lentil
I don't think 1) works. According to the docs, with AAS with custom containers, files in the mounted volumes get wiped when the container (re)starts. learn.microsoft.com/en-gb/azure/app-service/…Eras
P
3

Set WEBSITES_ENABLE_APP_SERVICE_STORAGE to true in appsettings and the home directory would be mapped from your outer kudo instance:

https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq

Pollard answered 2/7, 2018 at 8:6 Comment(1)
I used this, but still after few days I see my data was lost somehow.. so this is not reliable or production readyWartow
W
2

You have a few options:

  1. You could mount a file share inside the Docker container by creating a custom image, then storing data there. See these docs for more details.
  2. You could switch to the new container instances, as they provide volume support.
  3. You could switch to the Azure Container Service. This requires an orchestrator, like Kubernetes, and might be more work than you're looking for, but it also offers more flexibility, provides better reliability and scaling, and other benefits.
Weft answered 24/8, 2017 at 17:55 Comment(4)
Thanks, option 1 looks like it might have some potential although I'm assuming I then need to bake my file share access key into the docker build which makes it impossible to share with anyone.Lentil
You didn't mention sharing in your question, so it's hard to understand your scenario, but you might specify the file share key as an environment variable so that others can specify their own key.Weft
You're right I didn't I was just thinking if I was going to build a custom dockerfile for this I'd want to be able to share it. I'm going to try out creating a custom image with an environment variable and see how that works.Lentil
I don't think 1) works. According to the docs, with AAS with custom containers, files in the mounted volumes get wiped when the container (re)starts. learn.microsoft.com/en-gb/azure/app-service/…Eras
D
1

You have to use a shared volume that map the content of the container /var/lib/ghost directory to a host directory. This way, your data will persist in your host directory.

To do that, use the following command.

$ docker run -d --name some-ghost -p 3001:2368 -v /path/to/ghost/blog:/var/lib/ghost/content ghost:1-alpine
Despicable answered 24/8, 2017 at 13:30 Comment(1)
Unfortunately I'm not running from the command line, updated my question to clarifyLentil
A
1

I never worked with Azure, so I'm not 100 percent sure the following applies. But if you interface docker via the CLI there is a good chance it applies.

Persistency in docker is handled with volumes. They are basically mounts inside the container's file system tree to a directory on the outside. From your text I understand that you want store the content of the inside /var/lib/ghost path in /home/site/wwwroot on the outside. To do this you would call docker like this:

$ docker run [...] -v /var/lib/ghost:/home/site/wwwroot ghost

Abet answered 24/8, 2017 at 13:33 Comment(4)
Unfortunately I'm not running from the command line, updated my question to clarifyLentil
To bad. I found this in the Docker for Azure documentation: docs.docker.com/docker-for-azure/persistent-data-volumesAbet
Thanks, but I'm not using swarm I'm using an Azure Web App on Linux: learn.microsoft.com/en-us/azure/app-service-web/…Lentil
Looking at their CLI command documentation It seems they do not offer volume support yet. learn.microsoft.com/en-us/cli/azure/containerAbet
D
0

Unfortunately setting the persistent storage (or bring your own storage) to a specific path is currently not supported in Azure Web Apps on Linux. That's said, you can play with ssh and try and configure ghost to point to /home/ instead of /var/lib/. I have prepared a docker image here: https://hub.docker.com/r/elnably/ghost-on-azure that adds the ssh capability the dockerfile and code can be found here: https://github.com/ahmedelnably/ghost-on-azure/tree/master/1/alpine.

try it out by configuring you web app to use elnably/ghost-on-azure:latest, browse to the site (to start the container) and go to the ssh page .scm.azurewebsites.net, to learn more about SSH check this link: https://aka.ms/linux-ssh.

Dumas answered 26/8, 2017 at 1:1 Comment(2)
Thanks, that's super helpful. I've actually used a similar strategy where I've just taken a stock Node image and then connected to ssh via the scm and modified the container from there. I'm going to try mounting a file share and then installing into there from a custom image and see how I get on.Lentil
These links are dead now.Dvina

© 2022 - 2024 — McMap. All rights reserved.