soudis / datencockpit-docker

Dockerversion von Datencockpit (www.datencockpit.at)
GNU General Public License v3.0
5 stars 1 forks source link

How to save data outside of the docker container? #3

Open ovizii opened 6 years ago

ovizii commented 6 years ago

Sorry, Docker noob here. I am familiar with how to i.e. write data outside of containers if using i.e. this syntax: docker run -d --name=test -v /my/local/path/datencockpit-db:/var/lib/mysql

but I can't figure out how this works with the docker-compose.yml.sample file. Inside there I see these relevant lines but can't figure it out on my own:

volumes:
  datencockpit-db:
  datencockpit-html:

volumes:
      - datencockpit-db:/var/lib/mysql

volumes:
      - datencockpit-html:/var/www/html

Would you mind commenting on this please? lets assume I wanted to save the Db data here /my/local/path/datencockpit-db and the HTML Data here /my/local/path/datencockpit-html so that if I update or destroy and recreate the docker container I won't lose my data.

ovizii commented 6 years ago

After some googling, I "think" this would be the way to do it:

volumes:
      - /my/local/path/datencockpit-db:/var/lib/mysql

volumes:
      - /my/local/path/datencockpit-html:/var/www/html

not sure if I can then simply skip these lines:

volumes:
  datencockpit-db:
  datencockpit-html:
soudis commented 6 years ago

The way I use is to define so called named volumes. You can also create this without docker compose (https://docs.docker.com/engine/reference/commandline/volume_create/).

I'm not sure if mounting host directorys the way you are describing it would work. Because host directories cannot be prepopulated by the container, therefore they will be empty. For mysql, that is not a problem, for the html files for the media wiki it may be. Here are some advantages of named volumes over host mounted persistence directories:

If you are going for host mounted directories anyway, you can skip the "volumes" section of the docker-compose.yml.

You may also google named volumes to learn more about them.

ovizii commented 6 years ago

Thanks for the advice.

ovizii commented 6 years ago

I'm not sure if mounting host directorys the way you are describing it would work. Because host directories cannot be prepopulated by the container, therefore they will be empty. For mysql, that is not a problem, for the html files for the media wiki it may be.

Could you please expand on this? I did indeed hit a road block here, trying to use local folders.

This works:

services:

  db:
    image: mariadb
    restart: always
    volumes:
      - /home/ovi/docker/datencockpit/datencockpit-db:/var/lib/mysql

and yet this does not seem to work as the www folder remains empty:

  datencockpit:
    build:
      context: .
... skipped multiple lines here ...
    volumes:
      - /home/ovi/docker/datencockpit/datencockpit-html:/var/www/html

All my other containers so far work with this and I have persistent data which I can back up. I admit, none of my other containers use "build" so I have no experience with it. is there no way to make this work? Can you point me towards where this "build" happens? So far I have only found the Dockerfile but its unclear to me why that won't work the way I tried it.

edit is it possible that the base image (apache) gets pulled, modified (the data is copied into (var/www/html) and only afterwards the container is mounted thus my mounting an external path for /var/www/html comes afterwards? If that is the case, is there even a purpose of me trying to mount that volume externally? Is there anything valuable inside /var/www/html which I should persist across container versions or is it enough if my DB is kept safe?

soudis commented 6 years ago

ad your edit remarks: That is it. It makes sense to make the folder persistent if you plan on uploading media items, because they are not stored in the database