# Possible to add default data-scheme to Docker image?

**URL:** <https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535>\
**Category:** Support\
**Created:** [July 1, 2020, 4:43pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535 "2020-07-01T16:43:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommueller](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tommueller](https://discourse.getcockpit.com/u/tommueller)\
**Post date:** [July 1, 2020, 4:43pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/1 "2020-07-01T16:43:09Z")

</div>

We have our project running on different servers using the provided cockpit Docker image. Now on all these servers, we need the same data-structure in cockpit (currently about 2 singletons and 2 collections).  
Is it possible to add the data-scheme somehow to the Docker image, so that we don’t have to setup cockpit every single time?

Thanks!

---

<div class="post-metadata">

**Author:** ![gnagnu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/gnagnu/32/572_2.png) [@gnagnu](https://discourse.getcockpit.com/u/gnagnu)\
**Post date:** [July 6, 2020, 2:25pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/2 "2020-07-06T14:25:13Z")

</div>

Hi!  
I’m trying to achieve the same thing. Did you find a solution? Thanks  
Hang

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [July 9, 2020, 2:41pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/3 "2020-07-09T14:41:35Z")

</div>

@tommueller, @gnagnu Can you explain your use cases with some more details, please? Do you need only the structure (`/storage/collections/*.php` and `/storage/singletons/*.php`) or also some default data in the database? Data might need some importing scripts…

Some possible solutions:

You could create your own Docker image with the existing files and use that instead. Something like this:

Folder structure:

```nohighlight
storage/...
default.collection.php
Dockerfile
docker-compose.yml

```

```nohighlight
FROM agentejo/cockpit

COPY ./default.collection.php /var/www/html/storage/collections/default.collection.php

```

Or you could mount your default files into the container.

`docker run -d --name cockpit -p 8080:80 agentejo/cockpit -v "$PWD"/default.collection.php:/var/www/html/storage/collections/default.collection.php`

docker-compose.yml:

```auto
version: "3.7"

services:
  cockpit:
    image: agentejo/cockpit
    volumes:
      - ./storage:/var/www/html/storage
      - ./default.collection.php:/var/www/html/storage/collections/default.collection.php
    ports:
      - 8080:80

```

---

<div class="post-metadata">

**Author:** ![tommueller](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tommueller](https://discourse.getcockpit.com/u/tommueller)\
**Post date:** [July 21, 2020, 2:42pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/4 "2020-07-21T14:42:18Z")

</div>

Thanks @raffaelj!

The use case is, that we are providing a white-label software, that can be filled with content provided by cockpit. So for every new customer, we set up a new server, and run our software there, including cockpit, which runs within docker.

Now to net have to setup the singletons and collections with all the fields every time by hand, it would be nice to have a way to already include this into the docker image. Your first suggestions seems like it could work.

I thought that cockpit was using sqllite?! But collections and singleton schemas are stored in php files? Is there documentation about this somewhere?

Thanks! Tom

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [July 21, 2020, 3:57pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/5 "2020-07-21T15:57:22Z")

</div>

> [@tommueller](#):
>
> I thought that cockpit was using sqllite?! But collections and singleton schemas are stored in php files?

Yes. Only the data is stored in databases (MongoDB or SQLite). All the definition files are stored in

- `/storage/collections/*.collection.php`
- `/storage/singleton/*.singleton.php`
- `/storage/forms/*.form.php`

Data are things like

- users, some addon config, dashboard settings… - `/storage/data/cockpit.sqlite`
- collection entries - `/storage/data/collections.sqlite`
- singleton data - `/storage/data/cockpitdb.sqlite`
- form submissions - `/storage/data/forms.sqlite`
- locked entries (multi user setup) - `/storage/data/cockpit.memory.sqlite`

> [@tommueller](#):
>
> Is there documentation about this somewhere?

Good question 😉 I don’t think so, but now you know it.

---

<div class="post-metadata">

**Author:** ![tommueller](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tommueller](https://discourse.getcockpit.com/u/tommueller)\
**Post date:** [July 21, 2020, 4:24pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/6 "2020-07-21T16:24:00Z")

</div>

Thanks a bunch! That will be sufficient to get somewhere I guess.

It’ll take a while until I will find the time to implement it, but when I do I will try to leave some code here @gnagnu

---

<div class="post-metadata">

**Author:** ![gnagnu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/gnagnu/32/572_2.png) [@gnagnu](https://discourse.getcockpit.com/u/gnagnu)\
**Post date:** [July 25, 2020, 10:07am UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/7 "2020-07-25T10:07:11Z")

</div>

Thanks both! Very useful info

---

<div class="post-metadata">

**Author:** ![tommueller](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tommueller](https://discourse.getcockpit.com/u/tommueller)\
**Post date:** [August 10, 2020, 1:49pm UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/8 "2020-08-10T13:49:42Z")

</div>

I’ve been working on this finally now, but haven’t really found a good solution.

1. My first try was to extend the cockpit Docker image and copy the files into it. This does not work, because I have to use volumes and the volumes override any possible content in the folders.
2. What I am trying now is to have the files in the repo and mount them as volumes from there. This is also not ideal, as it then interacts with the files in my repo, so when switching branches etc. it might break. Also I don’t want to commit the content changes in cockpit into the repo obviously.

So the solution should probably be something like a shellscript, which copies the files to the volume-mount destination first and then starts cockpit with docker-compose, right?

---

<div class="post-metadata">

**Author:** ![tommueller](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tommueller](https://discourse.getcockpit.com/u/tommueller)\
**Post date:** [August 26, 2020, 8:45am UTC](https://discourse.getcockpit.com/t/possible-to-add-default-data-scheme-to-docker-image/1535/9 "2020-08-26T08:45:07Z")

</div>

Just wanted to give an update with my current solution. It is working fine, I am however not completely happy with it, as it seems a bit of dirty hack. So any suggestions / comments on how to get this a bit cleaner would be highly appreciated!  
I myself wasn’t able to find a cleaner solution, mostly because the `VOLUME` is already defined in the cockpit docker image that I am extending from, so I cannot copy anything to the folder anymore.

So I basically copy the assets to a tmp-folder in the image and execute an init-script each time the container is started, in which I check if the files already exist or not:

**DOCKERFILE**

```auto
FROM agentejo/cockpit:0.11.0

WORKDIR /tmp/initial-data
COPY ./assets/ .
CMD ["/bin/sh", "-c", "./initialize-data.sh && apache2-foreground"]

```

**initialize-data.sh**

```bash
#!/usr/bin/env sh
set -e

if [! -f /var/www/html/storage/collections/static_content.collection.php]; then
    cp -R /tmp/initial-data/storage/* /var/www/html/storage
fi

chown -R www-data:www-data /var/www/html/storage

```
