Possible to add default data-scheme to Docker image?

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?


1 Like

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

@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:

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


version: "3.7"

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

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

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

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

1 Like

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

Thanks both! Very useful info

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?

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:


FROM agentejo/cockpit:0.11.0

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


#!/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

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