0

Before anything, I have read this question and the related links in it, but I am still confused about how to resolve this on my setup.

I wrote my own docker file to install Archiva, which is very similar to this file. I created an image from the docker file using docker build -t archiva . and have a container which I run using docker run archiva. As seen in the docker file, the user data that I want to preserve is in a volume.

Now I want to upgrade to Archive 2.2.0. How can I update my container, so that the user-data thats in the volume is preserved? If I change the docker file by h=just changing the version number, and run the docker build again, it will just create another container.

Community
  • 1
  • 1
rgamber
  • 5,231
  • 8
  • 48
  • 92
  • 1
    Coud you post the command you use to run the docker image? If you used `docker run -v` to mount a host folder to the volume location, then you can reuse that host folder with your new container and data will be preserved. BTW for the terminology, `docker build` create a new "image", while `docker run` create a new "container" based on the image. – Xiongbing Jin Mar 08 '16 at 19:28
  • I don't use the `-v` flag in the run command, but I have it declared in the docker file itself. So I need to take it out of the docker file then? I thought form reading the documentation that it was either-or i.e. either put it in the docker file or use it with the `-v` flag. – rgamber Mar 08 '16 at 19:31
  • 1
    I think it is possible to use `docker run --volumes-from old_container new_image` to preserve the data. – Xiongbing Jin Mar 08 '16 at 19:43
  • So you are suggesting that I do create a new container, and just use the data from the old container? – rgamber Mar 08 '16 at 19:44
  • Yes I think that should work. Always make a backup first if your old container has important data. – Xiongbing Jin Mar 08 '16 at 19:48
  • Yeah, I guess I'll have to go with that! Thanks. I'll keep this question up to see if anyone has any other suggestions. – rgamber Mar 08 '16 at 19:48
  • Why not just run the commands to update your service in your current container? Using `docker exec -it CONT_NAME bash`? From your use case, it doesn't sound like you need a new container.... – CtheGood Mar 08 '16 at 20:09
  • Doing updates from inside container is supposed to be a bad practice! Correct me if I'm wrong. – rgamber Mar 08 '16 at 20:11

1 Answers1

1

Best practice

The option --volume of the docker-run enables sharing files between host and container(s) and especially preserve consistent [user] data.

The problem is ..

.. it appears that you are not using --volume and that the user data are in the image. (and that's a bad practice beacuse it leads to the situation you are in: unable to upgrade a service easily.

One solution (the best IMO) is

Back-up the user data

To use the command docker-cp: "Copy files/folders between a container and the local filesystem."

docker cp [--help] CONTAINER:SRC_PATH DEST_PATH

Upgrade your Dockerfile

By editing your Dockerfile and changing the version.

Use the --volume option

Use docker run -v /host/path/user-data:container/path/user-data archiva

And you're good!

Auzias
  • 3,064
  • 11
  • 34