2

I have a web application running in container. The application allows users to upload files. These files are stored in Docker volumes web_data1 and web_data2.

Due to changes in the application, I need to change the mountpoint of these volumes i.e. the data that were in /srv/app/web_data1_mountpoint, now need to be moved to /srv/app/web_data1_changed_mountpoint.

What is the proper way to do this?

docker-compose.yml

version: "3"

volumes:
  web_data1:
  web_data2:

services:
  web:
    build:
      context: .
      dockerfile: .docker/Dockerfile
    image: web-image
    ports:
      - 80:80
      - 443:443
    volumes:
      - web_data1:/srv/app/web_data1_mountpoint
      - web_data2:/srv/app/web_data2_mountpoint
Draex_
  • 3,011
  • 4
  • 32
  • 50

1 Answers1

4

That depends a bit of the image you are using. Just changing the volume would work in your docker-compose.yml like this:

volumes:
      - web_data1:/srv/app/web_data1_changed_mountpoint
      - web_data2:/srv/app/web_data2_changed_mountpoint

But I dont know, what your image does with the directory. Maybe something inside the image depends on the directory.

Mario
  • 275
  • 1
  • 10
  • I thought that changing the mountpoint like this would create a new volume and therefore my data would get lost. Is that wrong? – Draex_ Mar 16 '20 at 14:19
  • Just tested it with a local installation - your web_data1/web_data2 should stay persistent and would get mounted to the new mountpoint in your service. Alternatively you can mount your directory inside the container to a real directory on your host-system. Also you can add an extra mount to be sure: - web_data1:/srv/app/web_data1_mountpoint - web_data1:/srv/app/web_data1_changed_mountpoint – Mario Mar 16 '20 at 14:33