Docker with addons and persistent storage

Hello,

I’m having a bit of difficulty understanding how to set up a workflow for using Cockpit with Docker. I’m not very experienced with web development, but I’ve spent the entire day following tutorials and while it’s starting to make sense, I’m unable to connect everything in my head.

I feel like what I want to do is pretty common:

  • Set up some Collections and Singletons in Cockpit.
  • Write a couple of hooks or include addons to customize how Cockpit behaves.
  • (BONUS but not necessary) Populate some sample data for the Collections and Singletons.
  • Save all that into something I can deploy on a different server.

I’m trying to use Docker as it seems like that’s what that tool is for. Some questions:

  • If I use the image from Docker Hub, can I modify this to add addons? If so, how does this work? If not, is the idea to just make a git fork of the main project and add whatever addons I want in there and make a Docker image from my fork?
  • For persistent data, do I want to map the entire cockpit root dir to a Docker volume or just the storage subfolder? What’s the best practice here?
  • If I make my own fork, would it make sense to just push the SQLite files to git or should the data be separate?

I’m pretty confused into how this all fits together and would appreciate any suggestions, links, examples, etc. to help wrap my head around this.

Thanks in advance!

Ok I’ll answer my own question here! After a bit of trial and error, I have a setup I’m pretty happy with.

I set up a separate git repo with only:

config/
storage/
docker-compose.yml

The docker-compose.yml file looks like this:

version: "3.7"

services:
  cockpit:

    # https://hub.docker.com/r/agentejo/cockpit
    # https://github.com/agentejo/cockpit-docker
    image: agentejo/cockpit

    # let apache create files and folders with your user_id:user_group_id
    # In my case, I'm the default user with id 1000 and I'm a member of the group with gid 1000
    user: 1000:1000

    volumes:
      # mount storage folder into the docker container
      - ./storage:/var/www/html/storage
      - ./config/tags:/var/www/html/config/tags

    ports:
      - 8080:80

    stdin_open: true # docker run -i
    tty: true        # docker run -t

    # apache can't start without that fix if the user was changed
    # see https://hub.docker.com/_/php/ (scroll down to "Running as an arbitrary user")
    sysctls:
      - net.ipv4.ip_unprivileged_port_start=0

    # override the entrypoint, that tries to change the ownership to 33:33 after the container started
    # see https://github.com/agentejo/cockpit-docker/blob/master/entrypoint#L5
    entrypoint: ["apache2-foreground"]

So it pulls the “official” Cockpit image and adds in my custom modules and storage. I then run everything with docker-compose up -d and it’s good to go.

If I make any changes I can push them to the repo.

Note that if you copy the storage/ folder from the Cockpit download, you need to delete the .gitignore file in storage/data/ or else it won’t save your data.

2 Likes