How to know which data is within a docker container to be able to map it correctly as a volume

520 Views Asked by At

I'm trying to install bluespice wiki and wanted to persist the data outside of the container. https://hub.docker.com/r/bluespice/bluespice-free

To save some space on my host, I wanted to put some data on a S3 storage. As far as I understood the developer of the wiki have all the services directly within the container (Webserver, etc.)

So my idea would be to have the important data (e.g. webserver) on the host and the actually files (pictures, videos, posts) on the S3. Is this something which can be achieved? If so how would I best approach this? Currently I don't understand how I know the correct paths.

my docker-compose file looks like this currently:

services:
   bluespice:
     container_name: Bluespice-Wiki
     image: bluespice/bluespice-free:3.2
     command: -H unix:///var/run/docker.sock
     restart: always
     volumes:
       - /mnt/s3fs:/data 

This will put all data on the 3s storage and this is really slow and probably also not the smartes move. So my understanding would be to create something like this:

volumes:
  - <localshare>:/data/webserver
  - <s3share>:/data/www/datafiles

Hope someone understands my problem :)

1

There are 1 best solutions below

4
Akshay Hegde On

Here is demonstration for your better understanding:

Once after :

# docker-compose up -d

You can use any of the below to know container volumes available:

# docker inspect -f '{{ .Mounts }}'  <your-container-id-or-name>

# docker inspect <your-container-id-or-name> | jq --raw-output .[].Mounts

For example I have mariadb container:

root@sys:/home/akshay/Documents/test2# docker inspect 00f70198a466 | jq --raw-output .[].Mounts
[
  {
    "Type": "volume",
    "Name": "2a583fc243a9a2bb80cf45a80e5befbdc88db3b14026ff2349f80345f58c9562",
    "Source": "/var/lib/docker/volumes/2a583fc243a9a2bb80cf45a80e5befbdc88db3b14026ff2349f80345f58c9562/_data",
    "Destination": "/var/lib/mysql",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
  }
]

Here you can see Source: which is actual path on your Host, and Destination: is absolute path inside your container.

Now say for example if you wish to store on cloud initially stop your container, mount your external storage on host, move/copy contents in Source: if any needed.

then in volumes you just have to set path, for example

# creating local directory
# mkdir mysql-data

# copying contents whatever in volume
# cp -r /var/lib/docker/volumes/2a583fc243a9a2bb80cf45a80e5befbdc88db3b14026ff2349f80345f58c9562/_data mysql-data

# we copied data to directory of our interest
# instead of keeping in /var/lib/docker/volumes/...../_data
docker-compose down

inside your docker-compose.yml

volumes:
      # local mount
      - "./mysql-data:/var/lib/mysql"
 
      # path to your remote storage ex: upload directory
      - "/path/where/s3-bucket/mounted:/var/www/somesite/uploads/"

and then

# now we refer volumes in local directory
docker-compose up -d

If no volumes available, then just enter your container like below and find out absolute path of the directory which you wanted to persist the data outside of the container.

# with bash
# docker exec -it <your-container-id-or-name> bash

# or with shell
# docker exec -it <your-container-id-or-name> sh

# and then browser folders 
# for example

root@sys:~# docker exec -it 00f70198a466 bash

root@00f70198a466:/# pwd
/

root@00f70198a466:/# ls
bin  boot  dev  docker-entrypoint-initdb.d  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@00f70198a466:/# cd /var/lib/mysql/

root@00f70198a466:/var/lib/mysql# pwd
/var/lib/mysql